[llvm] 1c3fdb3 - Revert "[SCEV] Don't invalidate past dependency-breaking instructions"

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 07:35:10 PDT 2023


Author: Nikita Popov
Date: 2023-10-09T16:35:01+02:00
New Revision: 1c3fdb3d1e187e646f97a305771c48378c5df756

URL: https://github.com/llvm/llvm-project/commit/1c3fdb3d1e187e646f97a305771c48378c5df756
DIFF: https://github.com/llvm/llvm-project/commit/1c3fdb3d1e187e646f97a305771c48378c5df756.diff

LOG: Revert "[SCEV] Don't invalidate past dependency-breaking instructions"

Unforuntately, the assumption underlying this optimization is
incorrect for getSCEVAtScope(): A SCEVUnknown instruction with
operands that have constant loop exit values can evaluate to
a constant, thus creating a dependency from an "always unknown"
instruction.

Losing this optimization is quite unfortunate, but it doesn't
seem like there is any simple workaround for this.

Fixes #68260.

This reverts commit 3ddd1ffb721dd0ac3faa4a53c76b6904e862b7ab.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Transforms/IndVarSimplify/pr68260.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index ffa6cd746b25d47..13ad5b560ef965e 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4494,18 +4494,6 @@ void ScalarEvolution::insertValueToMap(Value *V, const SCEV *S) {
   }
 }
 
-/// Determine whether this instruction is either not SCEVable or will always
-/// produce a SCEVUnknown. We do not have to walk past such instructions when
-/// invalidating.
-static bool isAlwaysUnknown(const Instruction *I) {
-  switch (I->getOpcode()) {
-  case Instruction::Load:
-    return true;
-  default:
-    return false;
-  }
-}
-
 /// Return an existing SCEV if it exists, otherwise analyze the expression and
 /// create a new one.
 const SCEV *ScalarEvolution::getSCEV(Value *V) {
@@ -4513,11 +4501,7 @@ const SCEV *ScalarEvolution::getSCEV(Value *V) {
 
   if (const SCEV *S = getExistingSCEV(V))
     return S;
-  const SCEV *S = createSCEVIter(V);
-  assert((!isa<Instruction>(V) || !isAlwaysUnknown(cast<Instruction>(V)) ||
-          isa<SCEVUnknown>(S)) &&
-         "isAlwaysUnknown() instruction is not SCEVUnknown");
-  return S;
+  return createSCEVIter(V);
 }
 
 const SCEV *ScalarEvolution::getExistingSCEV(Value *V) {
@@ -4818,8 +4802,6 @@ static void PushDefUseChildren(Instruction *I,
   // Push the def-use children onto the Worklist stack.
   for (User *U : I->users()) {
     auto *UserInsn = cast<Instruction>(U);
-    if (isAlwaysUnknown(UserInsn))
-      continue;
     if (Visited.insert(UserInsn).second)
       Worklist.push_back(UserInsn);
   }

diff  --git a/llvm/test/Transforms/IndVarSimplify/pr68260.ll b/llvm/test/Transforms/IndVarSimplify/pr68260.ll
index 3b460209cf30def..fb185d2015b6467 100644
--- a/llvm/test/Transforms/IndVarSimplify/pr68260.ll
+++ b/llvm/test/Transforms/IndVarSimplify/pr68260.ll
@@ -4,7 +4,6 @@
 
 declare void @use(i32)
 
-; FIXME: This is a miscompile.
 define void @test() {
 ; CHECK-LABEL: define void @test() {
 ; CHECK-NEXT:  entry:
@@ -14,7 +13,7 @@ define void @test() {
 ; CHECK:       loop2:
 ; CHECK-NEXT:    br i1 false, label [[LOOP2]], label [[LOOP_LATCH:%.*]], !llvm.loop [[LOOP0:![0-9]+]]
 ; CHECK:       loop.latch:
-; CHECK-NEXT:    call void @use(i32 4)
+; CHECK-NEXT:    call void @use(i32 3)
 ; CHECK-NEXT:    br label [[LOOP2_1:%.*]]
 ; CHECK:       loop2.1:
 ; CHECK-NEXT:    br i1 false, label [[LOOP2_1]], label [[LOOP_LATCH_1:%.*]], !llvm.loop [[LOOP0]]


        


More information about the llvm-commits mailing list