about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-06-10 10:06:58 +0000
committerbors <bors@rust-lang.org>2021-06-10 10:06:58 +0000
commit0279cb11ed98bdc589c66572477fd27f1dd3e0ac (patch)
treeb4a6de143b517dc585c2381161cc378e37d92076
parentc5fbcd35a8217a17f6b63a22217ace06cf8f5f02 (diff)
parent4237a052330ddc39fc458b42238bdc50c8584d73 (diff)
downloadrust-0279cb11ed98bdc589c66572477fd27f1dd3e0ac.tar.gz
rust-0279cb11ed98bdc589c66572477fd27f1dd3e0ac.zip
Auto merge of #85741 - tmiasko:ssa, r=nagisa
Use preorder traversal when checking for SSA locals

Traverse blocks in topological sort of dominance partial order, to ensure that
local analyzer correctly identifies locals that are already in static single
assignment form, while avoiding dependency on implicit numeric order of blocks.

When rebuilding the standard library, this change reduces the number of locals
that require an alloca from 62452 to 62348.
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/analyze.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs
index 8a22a74f97c..49b5e8466be 100644
--- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs
@@ -18,7 +18,10 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
     let mir = fx.mir;
     let mut analyzer = LocalAnalyzer::new(fx);
 
-    for (bb, data) in mir.basic_blocks().iter_enumerated() {
+    // If there exists a local definition that dominates all uses of that local,
+    // the definition should be visited first. Traverse blocks in preorder which
+    // is a topological sort of dominance partial order.
+    for (bb, data) in traversal::preorder(&mir) {
         analyzer.visit_basic_block_data(bb, data);
     }