[llvm] c655134 - [IndVars] Forget SCEV for instruction and users before replacing it.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 18 09:38:31 PDT 2022
Author: Florian Hahn
Date: 2022-10-18T17:38:14+01:00
New Revision: c65513444b04df35d9bab5a3c60e9cdafe959e9a
URL: https://github.com/llvm/llvm-project/commit/c65513444b04df35d9bab5a3c60e9cdafe959e9a
DIFF: https://github.com/llvm/llvm-project/commit/c65513444b04df35d9bab5a3c60e9cdafe959e9a.diff
LOG: [IndVars] Forget SCEV for instruction and users before replacing it.
Extra invalidation is needed here to clear stale values to fix a
verification failure.
Fixes #58440.
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 08c48b02e591..11efcae02957 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -770,6 +770,7 @@ bool SimplifyIndvar::eliminateIdentitySCEV(Instruction *UseInst,
LLVM_DEBUG(dbgs() << "INDVARS: Eliminated identity: " << *UseInst << '\n');
+ SE->forgetValue(UseInst);
UseInst->replaceAllUsesWith(IVOperand);
++NumElimIdentity;
Changed = true;
diff --git a/llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll b/llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll
index 1877ae65557e..265a985d0f7f 100644
--- a/llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll
+++ b/llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -passes='loop(indvars,loop-deletion)' -S %s | FileCheck %s
+; RUN: opt -passes='loop(indvars,loop-deletion)' -verify-scev -S %s | FileCheck %s
; Make sure indvarsimplify properly forgets the exit value %p.2.lcssa phi after
; modifying it. Loop deletion is required to show the incorrect use of the cached
@@ -83,3 +83,40 @@ exit:
%inc.lcssa.lcssa = phi i8 [ %inc.lcssa, %loop.1.latch ]
ret i8 %inc.lcssa.lcssa
}
+
+define i32 @test_pr58440(i1 %c.0) {
+; CHECK-LABEL: @test_pr58440(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = or i32 0, 1
+; CHECK-NEXT: br label [[LOOP_1_HEADER:%.*]]
+; CHECK: loop.1.header.loopexit:
+; CHECK-NEXT: br label [[LOOP_1_HEADER]]
+; CHECK: loop.1.header:
+; CHECK-NEXT: br label [[LOOP_2_HEADER:%.*]]
+; CHECK: loop.2.header:
+; CHECK-NEXT: br i1 [[C_0:%.*]], label [[LOOP_2_LATCH:%.*]], label [[LOOP_1_HEADER_LOOPEXIT:%.*]]
+; CHECK: loop.2.latch:
+; CHECK-NEXT: br i1 false, label [[EXIT:%.*]], label [[LOOP_2_HEADER]]
+; CHECK: exit:
+; CHECK-NEXT: [[LCSSA:%.*]] = phi i32 [ [[TMP0]], [[LOOP_2_LATCH]] ]
+; CHECK-NEXT: ret i32 [[LCSSA]]
+;
+entry:
+ br label %loop.1.header
+
+loop.1.header:
+ %p.1 = phi i32 [ 0, %entry ], [ %p.2, %loop.2.header ]
+ br label %loop.2.header
+
+loop.2.header:
+ %p.2 = phi i32 [ %p.1, %loop.1.header ], [ %0, %loop.2.latch ]
+ br i1 %c.0, label %loop.2.latch, label %loop.1.header
+
+loop.2.latch:
+ %0 = or i32 %p.1, 1
+ br i1 false, label %exit, label %loop.2.header
+
+exit:
+ %lcssa = phi i32 [ %0, %loop.2.latch ]
+ ret i32 %lcssa
+}
More information about the llvm-commits
mailing list