Skip to content

Commit 8fb99af

Browse files
committed
Correct loop_headers logic.
1 parent 54b61d6 commit 8fb99af

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

compiler/rustc_mir_transform/src/jump_threading.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -743,15 +743,15 @@ enum Update {
743743
/// Compute the set of loop headers in the given body. We define a loop header as a block which has
744744
/// at least a predecessor which it dominates. This definition is only correct for reducible CFGs.
745745
/// But if the CFG is already irreducible, there is no point in trying much harder.
746-
/// is already irreducibl
746+
/// is already irreducible.
747747
fn loop_headers(body: &Body<'_>) -> BitSet<BasicBlock> {
748748
let mut loop_headers = BitSet::new_empty(body.basic_blocks.len());
749749
let dominators = body.basic_blocks.dominators();
750750
// Only visit reachable blocks.
751751
for (bb, bbdata) in traversal::preorder(body) {
752752
for succ in bbdata.terminator().successors() {
753753
if dominators.dominates(succ, bb) {
754-
loop_headers.insert(bb);
754+
loop_headers.insert(succ);
755755
}
756756
}
757757
}

tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
StorageLive(_1);
2020
_1 = DFA::A;
2121
StorageLive(_2);
22-
- goto -> bb1;
23-
+ goto -> bb7;
22+
goto -> bb1;
2423
}
2524

2625
bb1: {
@@ -64,11 +63,6 @@
6463
_3 = const ();
6564
StorageDead(_7);
6665
goto -> bb1;
67-
+ }
68-
+
69-
+ bb7: {
70-
+ _4 = discriminant(_1);
71-
+ goto -> bb4;
7266
}
7367
}
7468

tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
StorageLive(_1);
2020
_1 = DFA::A;
2121
StorageLive(_2);
22-
- goto -> bb1;
23-
+ goto -> bb7;
22+
goto -> bb1;
2423
}
2524

2625
bb1: {
@@ -64,11 +63,6 @@
6463
_3 = const ();
6564
StorageDead(_7);
6665
goto -> bb1;
67-
+ }
68-
+
69-
+ bb7: {
70-
+ _4 = discriminant(_1);
71-
+ goto -> bb4;
7266
}
7367
}
7468

0 commit comments

Comments
 (0)