summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2024-07-08 16:34:42 +0100
committerGitHub <noreply@github.com>2024-07-08 16:34:42 +0100
commit0577cdaa32b26c02e16822343e7039b999f43d58 (patch)
tree383adde435738d04f5418f18f409c9b53c20c3eb /llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
parentf5b9e11eb8ada0e7cc292f9ecd29a220d1265084 (diff)
[LV] Split checking if tail-folding is possible, collecting masked ops. (#77612)
Introduce new canFoldTail helper which only checks if tail-folding is possible, but without modifying MaskedOps. Just because tail-folding is possible doesn't mean the tail will be folded; that's up to the cost-model to decide. Separating the check if tail-folding is possible and preparing for tail-folding makes sure that MaskedOps is only populated when tail-folding is actually selected. PR: https://github.com/llvm/llvm-project/pull/77612
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp')
-rw-r--r--llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index d306524ae511..f54eebb2874a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -1543,7 +1543,7 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
return Result;
}
-bool LoopVectorizationLegality::prepareToFoldTailByMasking() {
+bool LoopVectorizationLegality::canFoldTailByMasking() const {
LLVM_DEBUG(dbgs() << "LV: checking if tail can be folded by masking.\n");
@@ -1586,23 +1586,31 @@ bool LoopVectorizationLegality::prepareToFoldTailByMasking() {
// The list of pointers that we can safely read and write to remains empty.
SmallPtrSet<Value *, 8> SafePointers;
- // Collect masked ops in temporary set first to avoid partially populating
- // MaskedOp if a block cannot be predicated.
+ // Check all blocks for predication, including those that ordinarily do not
+ // need predication such as the header block.
SmallPtrSet<const Instruction *, 8> TmpMaskedOp;
-
- // Check and mark all blocks for predication, including those that ordinarily
- // do not need predication such as the header block.
for (BasicBlock *BB : TheLoop->blocks()) {
if (!blockCanBePredicated(BB, SafePointers, TmpMaskedOp)) {
- LLVM_DEBUG(dbgs() << "LV: Cannot fold tail by masking as requested.\n");
+ LLVM_DEBUG(dbgs() << "LV: Cannot fold tail by masking.\n");
return false;
}
}
LLVM_DEBUG(dbgs() << "LV: can fold tail by masking.\n");
- MaskedOp.insert(TmpMaskedOp.begin(), TmpMaskedOp.end());
return true;
}
+void LoopVectorizationLegality::prepareToFoldTailByMasking() {
+ // The list of pointers that we can safely read and write to remains empty.
+ SmallPtrSet<Value *, 8> SafePointers;
+
+ // Mark all blocks for predication, including those that ordinarily do not
+ // need predication such as the header block.
+ for (BasicBlock *BB : TheLoop->blocks()) {
+ [[maybe_unused]] bool R = blockCanBePredicated(BB, SafePointers, MaskedOp);
+ assert(R && "Must be able to predicate block when tail-folding.");
+ }
+}
+
} // namespace llvm