[llvm] [LV] Don't predicate divs with invariant divisor when folding tail (PR #98904)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 03:34:39 PDT 2024
================
@@ -3348,40 +3348,48 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
return false;
// Can we prove this instruction is safe to unconditionally execute?
- // If not, we must use some form of predication.
+ if (I->getOpcode() == Instruction::Call)
+ return Legal->isMaskRequired(I);
+
+ if (isa<LoadInst, StoreInst>(I) && !Legal->isMaskRequired(I))
+ return false;
+
+ // TODO: We can use the loop-preheader as context point here and get
+ // context sensitive reasoning
+ if (isa<BranchInst, PHINode>(I) || isSafeToSpeculativelyExecute(I))
+ return false;
+
+ // If the instruction was executed conditionally in the original scalar loop,
+ // predication is needed.
+ if (Legal->blockNeedsPredication(I->getParent()))
+ return true;
+
+ // Tail folding may introduce additional predication, but we're guaranteed to
+ // always have at least one active lane. If the instruction in the original
+ // scalar loop was executed unconditionally, it may not need predication,
+ // depending on its operands.
----------------
ayalz wrote:
suggesting a rephrase, feel free to modify:
```suggestion
// All that remain are instructions with side-effects originally executed in the loop unconditionally, but now execute under a tail-fold mask (only) having at least one active lane (the first). If the side-effects of the instruction are invariant, executing it w/o (the tail-folding) mask is safe - it will cause the same side-effects as when masked.
```
https://github.com/llvm/llvm-project/pull/98904
More information about the llvm-commits
mailing list