[llvm] [LV] Handle partial reductions with predication (PR #194859)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 23 05:56:01 PDT 2026
================
@@ -6543,13 +6546,28 @@ static void transformToPartialReduction(const VPPartialReductionChain &Chain,
}
// Check if WidenRecipe is the final result of the reduction. If so look
- // through selects for predicated reductions.
- VPValue *Cond = nullptr;
- VPValue *ExitValue = cast_or_null<VPInstruction>(
- findUserOf(WidenRecipe, m_Select(m_VPValue(Cond), m_Specific(WidenRecipe),
- m_Specific(RdxPhi))));
- bool IsLastInChain = RdxPhi->getBackedgeValue() == WidenRecipe ||
- RdxPhi->getBackedgeValue() == ExitValue;
+ // through the select recipes introduced by tail-folding or predicated
+ // reductions for the BinOp's exit value.
+ VPValue *TailFoldCond = nullptr;
+ auto *ExitValue = cast_or_null<VPInstruction>(findUserOf(
+ WidenRecipe, m_Select(m_VPValue(TailFoldCond), m_Specific(WidenRecipe),
+ m_Specific(RdxPhi))));
+
+ VPValue *BlendCond = Chain.Blend ? Chain.Blend->getMask(0) : nullptr;
+ VPValue *Cond = TailFoldCond;
+
+ if (TailFoldCond && BlendCond) {
+ VPBuilder Builder(WidenRecipe);
+ Cond = Builder.createLogicalAnd(TailFoldCond, BlendCond,
+ WidenRecipe->getDebugLoc());
+ } else if (BlendCond) {
+ Cond = BlendCond;
+ }
+
+ bool IsLastInChain =
+ RdxPhi->getBackedgeValue() == WidenRecipe ||
+ RdxPhi->getBackedgeValue() == ExitValue ||
+ (Chain.Blend && RdxPhi->getBackedgeValue() == Chain.Blend);
----------------
MacDue wrote:
nit: (this is still valid for a null Chain.Blend)
```suggestion
RdxPhi->getBackedgeValue() == Chain.Blend;
```
https://github.com/llvm/llvm-project/pull/194859
More information about the llvm-commits
mailing list