[llvm] 6a42fb8 - [LV] Clarify code in isPredicatedInst (NFC) (#134251)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 02:46:20 PDT 2025


Author: Ramkumar Ramachandra
Date: 2025-04-08T10:46:17+01:00
New Revision: 6a42fb8fbfc075f28fa7d1d70bb51aef7f18e2f9

URL: https://github.com/llvm/llvm-project/commit/6a42fb8fbfc075f28fa7d1d70bb51aef7f18e2f9
DIFF: https://github.com/llvm/llvm-project/commit/6a42fb8fbfc075f28fa7d1d70bb51aef7f18e2f9.diff

LOG: [LV] Clarify code in isPredicatedInst (NFC) (#134251)

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 807136f6e0e47..72dbef1cffc5f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -3236,11 +3236,9 @@ bool LoopVectorizationCostModel::isScalarWithPredication(
 
 // TODO: Fold into LoopVectorizationLegality::isMaskRequired.
 bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
-  // If predication is not needed, avoid it.
   // TODO: We can use the loop-preheader as context point here and get
   // context sensitive reasoning for isSafeToSpeculativelyExecute.
-  if (!blockNeedsPredicationForAnyReason(I->getParent()) ||
-      isSafeToSpeculativelyExecute(I) ||
+  if (isSafeToSpeculativelyExecute(I) ||
       (isa<LoadInst, StoreInst, CallInst>(I) && !Legal->isMaskRequired(I)) ||
       isa<BranchInst, SwitchInst, PHINode, AllocaInst>(I))
     return false;
@@ -3250,6 +3248,10 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
   if (Legal->blockNeedsPredication(I->getParent()))
     return true;
 
+  // If we're not folding the tail by masking, predication is unnecessary.
+  if (!foldTailByMasking())
+    return false;
+
   // 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


        


More information about the llvm-commits mailing list