[PATCH] D83470: [LV] Fix versioning-for-unit-stide of loops with small trip count
Ayal Zaks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 03:29:36 PDT 2020
Ayal created this revision.
Ayal added reviewers: fhahn, gilr, uabelho.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This patch fixes D81345 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D81345>. The latter is chosen for now as the former requires refactoring.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D83470
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/optsize.ll
Index: llvm/test/Transforms/LoopVectorize/optsize.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/optsize.ll
+++ llvm/test/Transforms/LoopVectorize/optsize.ll
@@ -221,6 +221,32 @@
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() {
+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, undef
+ %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}
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4937,8 +4937,14 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83470.276687.patch
Type: text/x-patch
Size: 2061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200709/454e2c02/attachment.bin>
More information about the llvm-commits
mailing list