Skip to content

Commit 1c3fdb3

Browse files
committed
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 3ddd1ff.
1 parent 2a2b426 commit 1c3fdb3

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,30 +4494,14 @@ void ScalarEvolution::insertValueToMap(Value *V, const SCEV *S) {
44944494
}
44954495
}
44964496

4497-
/// Determine whether this instruction is either not SCEVable or will always
4498-
/// produce a SCEVUnknown. We do not have to walk past such instructions when
4499-
/// invalidating.
4500-
static bool isAlwaysUnknown(const Instruction *I) {
4501-
switch (I->getOpcode()) {
4502-
case Instruction::Load:
4503-
return true;
4504-
default:
4505-
return false;
4506-
}
4507-
}
4508-
45094497
/// Return an existing SCEV if it exists, otherwise analyze the expression and
45104498
/// create a new one.
45114499
const SCEV *ScalarEvolution::getSCEV(Value *V) {
45124500
assert(isSCEVable(V->getType()) && "Value is not SCEVable!");
45134501

45144502
if (const SCEV *S = getExistingSCEV(V))
45154503
return S;
4516-
const SCEV *S = createSCEVIter(V);
4517-
assert((!isa<Instruction>(V) || !isAlwaysUnknown(cast<Instruction>(V)) ||
4518-
isa<SCEVUnknown>(S)) &&
4519-
"isAlwaysUnknown() instruction is not SCEVUnknown");
4520-
return S;
4504+
return createSCEVIter(V);
45214505
}
45224506

45234507
const SCEV *ScalarEvolution::getExistingSCEV(Value *V) {
@@ -4818,8 +4802,6 @@ static void PushDefUseChildren(Instruction *I,
48184802
// Push the def-use children onto the Worklist stack.
48194803
for (User *U : I->users()) {
48204804
auto *UserInsn = cast<Instruction>(U);
4821-
if (isAlwaysUnknown(UserInsn))
4822-
continue;
48234805
if (Visited.insert(UserInsn).second)
48244806
Worklist.push_back(UserInsn);
48254807
}

llvm/test/Transforms/IndVarSimplify/pr68260.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
declare void @use(i32)
66

7-
; FIXME: This is a miscompile.
87
define void @test() {
98
; CHECK-LABEL: define void @test() {
109
; CHECK-NEXT: entry:
@@ -14,7 +13,7 @@ define void @test() {
1413
; CHECK: loop2:
1514
; CHECK-NEXT: br i1 false, label [[LOOP2]], label [[LOOP_LATCH:%.*]], !llvm.loop [[LOOP0:![0-9]+]]
1615
; CHECK: loop.latch:
17-
; CHECK-NEXT: call void @use(i32 4)
16+
; CHECK-NEXT: call void @use(i32 3)
1817
; CHECK-NEXT: br label [[LOOP2_1:%.*]]
1918
; CHECK: loop2.1:
2019
; CHECK-NEXT: br i1 false, label [[LOOP2_1]], label [[LOOP_LATCH_1:%.*]], !llvm.loop [[LOOP0]]

0 commit comments

Comments
 (0)