[PATCH] D137651: [LoopFlatten] Forget SCEV value for removed incomming values of phi
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 8 08:50:10 PST 2022
StephenFan created this revision.
StephenFan added reviewers: nikic, fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Fixes: https://github.com/llvm/llvm-project/issues/58865
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137651
Files:
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
llvm/test/Transforms/LoopFlatten/pr58865.ll
Index: llvm/test/Transforms/LoopFlatten/pr58865.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopFlatten/pr58865.ll
@@ -0,0 +1,28 @@
+; RUN: opt -loop-flatten -verify-scev < %s
+
+define void @sum_2d(ptr %p) {
+entry:
+ br label %outer
+
+outer: ; preds = %outer.latch, %entry
+ %sum.04 = phi i16 [ 0, %entry ], [ %0, %outer.latch ]
+ %outer.iv = phi i16 [ 0, %entry ], [ %outer.iv.next, %outer.latch ]
+ br label %inner
+
+inner: ; preds = %inner, %outer
+ %sum.12 = phi i16 [ %sum.04, %outer ], [ %0, %inner ]
+ %inner.iv = phi i16 [ 0, %outer ], [ %inner.iv.next, %inner ]
+ %0 = load i16, ptr %p, align 1
+ %inner.iv.next = add nsw i16 %inner.iv, 1
+ %cmp2 = icmp slt i16 %inner.iv, 0
+ br i1 %cmp2, label %inner, label %outer.latch
+
+outer.latch: ; preds = %inner
+ %outer.iv.next = add nsw i16 %outer.iv, 1
+ %cmp = icmp slt i16 %outer.iv.next, 0
+ br i1 %cmp, label %outer, label %exit
+
+exit: ; preds = %outer.latch
+ ret void
+
+}
Index: llvm/lib/Transforms/Scalar/LoopFlatten.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFlatten.cpp
+++ llvm/lib/Transforms/Scalar/LoopFlatten.cpp
@@ -722,12 +722,13 @@
// Fix up PHI nodes that take values from the inner loop back-edge, which
// we are about to remove.
- FI.InnerInductionPHI->removeIncomingValue(FI.InnerLoop->getLoopLatch());
+ SE->forgetValue(
+ FI.InnerInductionPHI->removeIncomingValue(FI.InnerLoop->getLoopLatch()));
// The old Phi will be optimised away later, but for now we can't leave
// leave it in an invalid state, so are updating them too.
for (PHINode *PHI : FI.InnerPHIsToTransform)
- PHI->removeIncomingValue(FI.InnerLoop->getLoopLatch());
+ SE->forgetValue(PHI->removeIncomingValue(FI.InnerLoop->getLoopLatch()));
// Modify the trip count of the outer loop to be the product of the two
// trip counts.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137651.474021.patch
Type: text/x-patch
Size: 2122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221108/b476e4d1/attachment.bin>
More information about the llvm-commits
mailing list