Skip to content

Commit b164143

Browse files
committed
[SimpleLoopUnswitch] Preserve one PHI when removing a predecessor of a BB
1 parent b2eb1f4 commit b164143

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ static void deleteDeadBlocksFromLoop(Loop &L,
17161716
auto *BB = DeathCandidates.pop_back_val();
17171717
if (!DeadBlockSet.count(BB) && !DT.isReachableFromEntry(BB)) {
17181718
for (BasicBlock *SuccBB : successors(BB)) {
1719-
SuccBB->removePredecessor(BB);
1719+
SuccBB->removePredecessor(BB, /*KeepOneInputPHIs*/ true);
17201720
DeathCandidates.push_back(SuccBB);
17211721
}
17221722
DeadBlockSet.insert(BB);

llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-pred-removed.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>),print<memoryssa>' -verify-memoryssa -disable-output -S < %s 2>&1 | FileCheck %s
2+
; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>,licm)' -verify-memoryssa -disable-output -S
23

3-
; CHECK: preds = %bb2{{$}}
4+
; Check that SimpleLoopUnswitch preserves the MemoryDef of `call i32 @bar()` by preserving the PHI node.
5+
; Also, check that executing LICM after SimpleLoopUnswitch does not result in a crash.
6+
7+
; CHECK: %unswitched.select = phi ptr [ @bar, %bb2 ]
48
; CHECK-NEXT: MemoryDef
5-
; CHECK-NEXT: call i32 @bar()
9+
; CHECK-NEXT: call i32 %unswitched.select()
610

711
define i32 @foo(i1 %arg, ptr %arg1) {
812
bb:

0 commit comments

Comments
 (0)