[llvm] [LV] Invalidate disposition of SCEV values after loop vectorization (PR #69230)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 11:22:15 PDT 2023
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/69230
>From 14aff24488bb99314410e17bd45a4188e4c9d100 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 17 Oct 2023 01:21:12 +0800
Subject: [PATCH 1/3] [LV] Add pre-commit tests for PR69097.
---
.../Transforms/Vectorize/LoopVectorize.cpp | 5 +++--
.../LoopVectorize/scev-invalidation.ll | 22 +++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/Transforms/LoopVectorize/scev-invalidation.ll
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 2ca7e75f97f0f02..f62942b4a200c01 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10389,8 +10389,9 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
PA.preserve<DominatorTreeAnalysis>();
PA.preserve<ScalarEvolutionAnalysis>();
-#ifdef EXPENSIVE_CHECKS
- SE.verify();
+#ifndef NDEBUG
+ if (VerifySCEV)
+ SE.verify();
#endif
}
diff --git a/llvm/test/Transforms/LoopVectorize/scev-invalidation.ll b/llvm/test/Transforms/LoopVectorize/scev-invalidation.ll
new file mode 100644
index 000000000000000..08163293c14e85e
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/scev-invalidation.ll
@@ -0,0 +1,22 @@
+; 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
+
+; CHECK-LABEL: @main(
+; CHECK: vector.body
+define i32 @main(i32 %.pre) {
+entry:
+ br label %for.body
+
+for.body:
+ %g.019 = phi i16 [ 0, %entry ], [ %dec7, %for.body ]
+ %and = and i32 %.pre, 40
+ %0 = sub i32 0, %and
+ %dec7 = add i16 %g.019, 1
+ %cmp.not = icmp eq i16 %dec7, 0
+ br i1 %cmp.not, label %for.inc16, label %for.body
+
+for.inc16:
+ %1 = phi i32 [ %inc, %for.inc16 ], [ 0, %for.body ]
+ %inc = add i32 %1, 1
+ %add12 = add i32 %0, %1
+ br label %for.inc16
+}
>From 4ee333fd252247089d1e02f8eef30ad5374b2519 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 17 Oct 2023 01:35:36 +0800
Subject: [PATCH 2/3] [LV] Invalidate disposition of SCEV values after loop
vectorization.
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f62942b4a200c01..685c561fc4d2e1b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -3543,6 +3543,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
// Forget the original basic block.
PSE.getSE()->forgetLoop(OrigLoop);
+ PSE.getSE()->forgetBlockAndLoopDispositions();
// After vectorization, the exit blocks of the original loop will have
// additional predecessors. Invalidate SCEVs for the exit phis in case SE
>From 0a712a0a65d59f5066a4d436c9ec3f289659fbe8 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 17 Oct 2023 02:21:33 +0800
Subject: [PATCH 3/3] fixup! [LV] Invalidate disposition of SCEV values after
loop vectorization.
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 685c561fc4d2e1b..aa435b0d47aa599 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10340,8 +10340,14 @@ LoopVectorizeResult LoopVectorizePass::runImpl(
Changed |= CFGChanged |= processLoop(L);
- if (Changed)
+ if (Changed) {
LAIs->clear();
+
+#ifndef NDEBUG
+ if (VerifySCEV)
+ SE->verify();
+#endif
+ }
}
// Process each loop nest in the function.
@@ -10389,11 +10395,6 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
PA.preserve<LoopAnalysis>();
PA.preserve<DominatorTreeAnalysis>();
PA.preserve<ScalarEvolutionAnalysis>();
-
-#ifndef NDEBUG
- if (VerifySCEV)
- SE.verify();
-#endif
}
if (Result.MadeCFGChange) {
More information about the llvm-commits
mailing list