[PATCH] D93477: [LoopVectorizer] Fix invalid scenario that is allowed to interleave
Danilo Carvalho Grael via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 17 11:28:25 PST 2020
dancgr updated this revision to Diff 312565.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93477/new/
https://reviews.llvm.org/D93477
Files:
llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8066,6 +8066,13 @@
IC = CM.selectInterleaveCount(VF.Width, VF.Cost, LVI);
}
+ // Check if it is legal to interleave the loop.
+ if (IC > 1 && !LVL.isLegalToInterleave()) {
+ LLVM_DEBUG(dbgs() << "LV: Not vectorizing: Can't interleave reduction.\n");
+ Hints.emitRemarkWithHints();
+ return false;
+ }
+
// Identify the diagnostic messages that should be produced.
std::pair<StringRef, std::string> VecDiagMsg, IntDiagMsg;
bool VectorizeLoop = true, InterleaveLoop = true;
Index: llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -1263,4 +1263,18 @@
return true;
}
+bool LoopVectorizationLegality::isLegalToInterleave() {
+ // Check if reduction has invalid type for interleaving.
+ for (auto &Reduction : *getReductionVars()) {
+ auto Descriptor = Reduction.second;
+ auto ComputedType = Descriptor.getRecurrenceType();
+ auto IsSigned = Descriptor.isSigned();
+ // Eliminate degenerate types.
+ if (ComputedType->isIntegerTy(1) && IsSigned) {
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace llvm
Index: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
===================================================================
--- llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
+++ llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
@@ -313,6 +313,8 @@
// Returns true if the NoNaN attribute is set on the function.
bool hasFunNoNaNAttr() const { return HasFunNoNaNAttr; }
+ bool isLegalToInterleave();
+
private:
/// Return true if the pre-header, exiting and latch blocks of \p Lp and all
/// its nested loops are considered legal for vectorization. These legal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93477.312565.patch
Type: text/x-patch
Size: 2144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201217/9ee240a3/attachment.bin>
More information about the llvm-commits
mailing list