Skip to content

Commit f661ce2

Browse files
committed
[LoopPredication] Fix MemorySSA crash in predicateLoopExits
The attached testcase crashes without the patch (Not the same accesses in the same order). When we move instructions before another instruction, we also need to update the memory accesses corresponding to it. Reviewed-By: asbirlea Differential Revision: https://reviews.llvm.org/D109197
1 parent 1104e32 commit f661ce2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

llvm/lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,10 @@ bool LoopPredication::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
11271127
// modifying the operand is legal.
11281128
auto *IP = cast<Instruction>(WidenableBR->getCondition());
11291129
IP->moveBefore(WidenableBR);
1130+
if (MSSAU)
1131+
if (auto *MUD = MSSAU->getMemorySSA()->getMemoryAccess(IP))
1132+
MSSAU->moveToPlace(MUD, WidenableBR->getParent(),
1133+
MemorySSA::BeforeTerminator);
11301134
Rewriter.setInsertPoint(IP);
11311135
IRBuilder<> B(IP);
11321136

llvm/test/Transforms/LoopPredication/predicate-exits.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,34 @@ exit:
10821082
ret i32 %result
10831083
}
10841084

1085+
define void @test_memssa() {
1086+
bb:
1087+
%tmp = call i1 @llvm.experimental.widenable.condition()
1088+
%tmp1 = call i1 @llvm.experimental.widenable.condition()
1089+
br i1 %tmp, label %bb3, label %bb2
1090+
1091+
bb2: ; preds = %bb
1092+
unreachable
1093+
1094+
bb3: ; preds = %bb
1095+
br label %bb4
1096+
1097+
bb4: ; preds = %bb6, %bb3
1098+
%tmp5 = phi i32 [ %tmp7, %bb6 ], [ 0, %bb3 ]
1099+
br i1 undef, label %bb10, label %bb6
1100+
1101+
bb6: ; preds = %bb4
1102+
%tmp7 = add nuw nsw i32 %tmp5, 1
1103+
%tmp8 = icmp ult i32 %tmp7, undef
1104+
br i1 %tmp8, label %bb4, label %bb9
1105+
1106+
bb9: ; preds = %bb6
1107+
ret void
1108+
1109+
bb10: ; preds = %bb4
1110+
ret void
1111+
}
1112+
10851113

10861114

10871115
declare void @unknown()

0 commit comments

Comments
 (0)