[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:38 PDT 2024


================
@@ -3348,40 +3348,48 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
     return false;
----------------
ayalz wrote:

```suggestion
  // If predication is not needed, avoid it.
  if (!blockNeedsPredicationForAnyReason(I->getParent())
      || isSafeToSpeculativelyExecute(I))
      || !Legal->isMaskRequired(I)
      || isa<BranchInst, PHINode>(I))
    return false;
```
should the case of `I` being isSafeToSpeculativelyExecute() be handled here at the outset along with the case of `I`'s block not needing predication for any reason?

Legal's isMaskRequired() deals only with load, stores, and calls (in particular "assume" intrinsics - which get dropped rather than predicated), and is tail-folding aware. Should originally unconditional loads and stores (of invariant values) from invariant addresses be excluded from MaskedOps? I.e., should Legal's blockCanBePredicated() take care of unmasking such loads and stores under tail-folding, alongside its unmasking of loads from safe pointers? Furthermore, is the distinction between CM.isPredicatedInst(I) and Legal.isMaskRequired(I) clear and desired, or could the collection of all MaskedOps/PredicatedInsts be done once? Masks were and still are introduced only where necessary, as a functional requirement rather than a performance preference.

https://github.com/llvm/llvm-project/pull/98904


More information about the llvm-commits mailing list