Skip to content

Commit 4718b40

Browse files
authored
[LV] Invalidate disposition of SCEV values after loop vectorization (#69230)
This PR fixes the assertion failure of `SE.verify()` after loop vectorization.
1 parent 5db4779 commit 4718b40

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
35433543

35443544
// Forget the original basic block.
35453545
PSE.getSE()->forgetLoop(OrigLoop);
3546+
PSE.getSE()->forgetBlockAndLoopDispositions();
35463547

35473548
// After vectorization, the exit blocks of the original loop will have
35483549
// additional predecessors. Invalidate SCEVs for the exit phis in case SE
@@ -10339,8 +10340,14 @@ LoopVectorizeResult LoopVectorizePass::runImpl(
1033910340

1034010341
Changed |= CFGChanged |= processLoop(L);
1034110342

10342-
if (Changed)
10343+
if (Changed) {
1034310344
LAIs->clear();
10345+
10346+
#ifndef NDEBUG
10347+
if (VerifySCEV)
10348+
SE->verify();
10349+
#endif
10350+
}
1034410351
}
1034510352

1034610353
// Process each loop nest in the function.
@@ -10388,10 +10395,6 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
1038810395
PA.preserve<LoopAnalysis>();
1038910396
PA.preserve<DominatorTreeAnalysis>();
1039010397
PA.preserve<ScalarEvolutionAnalysis>();
10391-
10392-
#ifdef EXPENSIVE_CHECKS
10393-
SE.verify();
10394-
#endif
1039510398
}
1039610399

1039710400
if (Result.MadeCFGChange) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: opt < %s -passes="require<scalar-evolution>,print<scalar-evolution>,loop-vectorize" --verify-scev -force-vector-interleave=2 -force-vector-width=8 -S | FileCheck %s
2+
3+
; CHECK-LABEL: @main(
4+
; CHECK: vector.body
5+
define i32 @main(i32 %.pre) {
6+
entry:
7+
br label %for.body
8+
9+
for.body:
10+
%g.019 = phi i16 [ 0, %entry ], [ %dec7, %for.body ]
11+
%and = and i32 %.pre, 40
12+
%0 = sub i32 0, %and
13+
%dec7 = add i16 %g.019, 1
14+
%cmp.not = icmp eq i16 %dec7, 0
15+
br i1 %cmp.not, label %for.inc16, label %for.body
16+
17+
for.inc16:
18+
%1 = phi i32 [ %inc, %for.inc16 ], [ 0, %for.body ]
19+
%inc = add i32 %1, 1
20+
%add12 = add i32 %0, %1
21+
br label %for.inc16
22+
}

0 commit comments

Comments
 (0)