[llvm] [LoopVectorizer] Allow partial reductions to be made in predicated loops (PR #124268)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 09:10:54 PST 2025


================
@@ -8904,6 +8897,12 @@ VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
       isa<VPPartialReductionRecipe>(BinOpRecipe))
     std::swap(BinOp, Accumulator);
 
+  VPValue *Mask = getBlockInMask(Reduction->getParent());
+  if (Mask) {
+    VPValue *Zero =
+        Plan.getOrAddLiveIn(ConstantInt::get(Reduction->getType(), 0));
+    BinOp = Builder.createSelect(Mask, BinOp, Zero, Reduction->getDebugLoc());
+  }
----------------
MacDue wrote:

Not sure, but should this be (or similar):
```suggestion
  if (CM.isPredicatedInst(Reduction)) {
    VPValue *Mask = getBlockInMask(Reduction->getParent());
    VPValue *Zero =
        Plan.getOrAddLiveIn(ConstantInt::get(Reduction->getType(), 0));
    BinOp = Builder.createSelect(Mask, BinOp, Zero, Reduction->getDebugLoc());
  }
```
Just because I see a `Trying to access mask for block without one.` assert in `getBlockInMask()`, and I wonder if it's possible to hit that somehow. 

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


More information about the llvm-commits mailing list