[llvm] 82a5157 - [LV] Fixing versioning-for-unit-stide of loops with small trip count
Ayal Zaks via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 12 10:42:15 PDT 2020
Author: Ayal Zaks
Date: 2020-07-12T19:51:47+03:00
New Revision: 82a5157ff1650e3366f7a9c619269766ad1d5e93
URL: https://github.com/llvm/llvm-project/commit/82a5157ff1650e3366f7a9c619269766ad1d5e93
DIFF: https://github.com/llvm/llvm-project/commit/82a5157ff1650e3366f7a9c619269766ad1d5e93.diff
LOG: [LV] Fixing versioning-for-unit-stide of loops with small trip count
This patch fixes D81345 and PR46652.
If a loop with a small trip count is compiled w/o -Os/-Oz, Loop Access Analysis
still generates runtime checks for unit strides that will version the loop.
In such cases, the loop vectorizer should either re-run the analysis or bail-out
from vectorizing the loop, as done prior to D81345. The latter is applied for
now as the former requires refactoring.
Differential Revision: https://reviews.llvm.org/D83470
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/optsize.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10e690d56ffd..35af8e425778 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4949,8 +4949,14 @@ bool LoopVectorizationCostModel::runtimeChecksRequired() {
return true;
}
- assert(Legal->getLAI()->getSymbolicStrides().empty() &&
- "Specializing for stride == 1 under -Os/-Oz");
+ // FIXME: Avoid specializing for stride==1 instead of bailing out.
+ if (!Legal->getLAI()->getSymbolicStrides().empty()) {
+ reportVectorizationFailure("Runtime stride check for small trip count",
+ "runtime stride == 1 checks needed. Enable vectorization of "
+ "this loop without such check by compiling with -Os/-Oz",
+ "CantVersionLoopWithOptForSize", ORE, TheLoop);
+ return true;
+ }
return false;
}
diff --git a/llvm/test/Transforms/LoopVectorize/optsize.ll b/llvm/test/Transforms/LoopVectorize/optsize.ll
index 8def1ab0a0e8..0e88f362746f 100644
--- a/llvm/test/Transforms/LoopVectorize/optsize.ll
+++ b/llvm/test/Transforms/LoopVectorize/optsize.ll
@@ -221,6 +221,32 @@ for.end:
ret void
}
+; PR46652: Check that the need for stride==1 check prevents vectorizing a loop
+; having tiny trip count, when compiling w/o -Os/-Oz.
+; CHECK-LABEL: @pr46652
+; CHECK-NOT: vector.scevcheck
+; CHECK-NOT: vector.body
+; CHECK-LABEL: for.body
+
+ at g = external global [1 x i16], align 1
+
+define void @pr46652(i16 %stride) {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %l1.02 = phi i16 [ 1, %entry ], [ %inc9, %for.body ]
+ %mul = mul nsw i16 %l1.02, %stride
+ %arrayidx6 = getelementptr inbounds [1 x i16], [1 x i16]* @g, i16 0, i16 %mul
+ %0 = load i16, i16* %arrayidx6, align 1
+ %inc9 = add nuw nsw i16 %l1.02, 1
+ %exitcond.not = icmp eq i16 %inc9, 16
+ br i1 %exitcond.not, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ ret void
+}
+
!llvm.module.flags = !{!0}
!0 = !{i32 1, !"ProfileSummary", !1}
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
More information about the llvm-commits
mailing list