From 8fb99afb0219846f98a82059de2f0808e4c0f61f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 20 Oct 2023 15:24:09 +0000 Subject: [PATCH] Correct loop_headers logic. --- compiler/rustc_mir_transform/src/jump_threading.rs | 4 ++-- .../jump_threading.dfa.JumpThreading.panic-abort.diff | 8 +------- .../jump_threading.dfa.JumpThreading.panic-unwind.diff | 8 +------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 5a5ca6fa870..83af640f777 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -743,7 +743,7 @@ enum Update { /// Compute the set of loop headers in the given body. We define a loop header as a block which has /// at least a predecessor which it dominates. This definition is only correct for reducible CFGs. /// But if the CFG is already irreducible, there is no point in trying much harder. -/// is already irreducibl +/// is already irreducible. fn loop_headers(body: &Body<'_>) -> BitSet { let mut loop_headers = BitSet::new_empty(body.basic_blocks.len()); let dominators = body.basic_blocks.dominators(); @@ -751,7 +751,7 @@ fn loop_headers(body: &Body<'_>) -> BitSet { for (bb, bbdata) in traversal::preorder(body) { for succ in bbdata.terminator().successors() { if dominators.dominates(succ, bb) { - loop_headers.insert(bb); + loop_headers.insert(succ); } } } diff --git a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff index 01bddc9a173..ad5846c97de 100644 --- a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff +++ b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff @@ -19,8 +19,7 @@ StorageLive(_1); _1 = DFA::A; StorageLive(_2); -- goto -> bb1; -+ goto -> bb7; + goto -> bb1; } bb1: { @@ -64,11 +63,6 @@ _3 = const (); StorageDead(_7); goto -> bb1; -+ } -+ -+ bb7: { -+ _4 = discriminant(_1); -+ goto -> bb4; } } diff --git a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff index 01bddc9a173..ad5846c97de 100644 --- a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff +++ b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff @@ -19,8 +19,7 @@ StorageLive(_1); _1 = DFA::A; StorageLive(_2); -- goto -> bb1; -+ goto -> bb7; + goto -> bb1; } bb1: { @@ -64,11 +63,6 @@ _3 = const (); StorageDead(_7); goto -> bb1; -+ } -+ -+ bb7: { -+ _4 = discriminant(_1); -+ goto -> bb4; } }