[llvm] beba307 - [LSR] Clear SCEVExpander before deleting phi nodes
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 12 08:24:29 PDT 2024
Author: Nikita Popov
Date: 2024-03-12T16:24:10+01:00
New Revision: beba307c5bc206168bdea3b893e02ea31579fe62
URL: https://github.com/llvm/llvm-project/commit/beba307c5bc206168bdea3b893e02ea31579fe62
DIFF: https://github.com/llvm/llvm-project/commit/beba307c5bc206168bdea3b893e02ea31579fe62.diff
LOG: [LSR] Clear SCEVExpander before deleting phi nodes
Fixes https://github.com/llvm/llvm-project/issues/84709.
Added:
llvm/test/Transforms/LoopStrengthReduce/pr84709.ll
Modified:
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 8b078ddc4e747e..c4e1a0db8b3230 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -6971,6 +6971,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE,
Rewriter.setDebugType(DEBUG_TYPE);
#endif
unsigned numFolded = Rewriter.replaceCongruentIVs(L, &DT, DeadInsts, &TTI);
+ Rewriter.clear();
if (numFolded) {
Changed = true;
RecursivelyDeleteTriviallyDeadInstructionsPermissive(DeadInsts, &TLI,
@@ -6989,6 +6990,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE,
SCEVExpander Rewriter(SE, DL, "lsr", true);
int Rewrites = rewriteLoopExitValues(L, &LI, &TLI, &SE, &TTI, Rewriter, &DT,
UnusedIndVarInLoop, DeadInsts);
+ Rewriter.clear();
if (Rewrites) {
Changed = true;
RecursivelyDeleteTriviallyDeadInstructionsPermissive(DeadInsts, &TLI,
diff --git a/llvm/test/Transforms/LoopStrengthReduce/pr84709.ll b/llvm/test/Transforms/LoopStrengthReduce/pr84709.ll
new file mode 100644
index 00000000000000..99794d01242c2a
--- /dev/null
+++ b/llvm/test/Transforms/LoopStrengthReduce/pr84709.ll
@@ -0,0 +1,34 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -passes=loop-reduce < %s | FileCheck %s
+
+; Make sure it does not assert.
+define i64 @test() {
+; CHECK-LABEL: define i64 @test() {
+; CHECK-NEXT: bb:
+; CHECK-NEXT: br label [[BB1:%.*]]
+; CHECK: bb1:
+; CHECK-NEXT: br label [[BB2:%.*]]
+; CHECK: bb2:
+; CHECK-NEXT: br i1 true, label [[BB5:%.*]], label [[BB2]]
+; CHECK: bb5:
+; CHECK-NEXT: br label [[BB1]]
+;
+bb:
+ br label %bb1
+
+bb1:
+ %phi = phi i8 [ %zext6, %bb5 ], [ 0, %bb ]
+ br label %bb2
+
+bb2:
+ %phi3 = phi i8 [ %add, %bb2 ], [ %phi, %bb1 ]
+ %phi4 = phi i32 [ 0, %bb2 ], [ 1, %bb1 ]
+ %add = add i8 %phi3, 1
+ br i1 true, label %bb5, label %bb2
+
+bb5:
+ %zext = zext i8 %add to i32
+ %icmp = icmp sge i32 %phi4, 0
+ %zext6 = zext i1 %icmp to i8
+ br label %bb1
+}
More information about the llvm-commits
mailing list