[llvm] [VPlan] Optimize FindLast of (binop %IV, live-in) by sinking. (PR #183911)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 07:04:19 PDT 2026
================
@@ -5732,27 +5771,35 @@ void VPlanTransforms::optimizeFindIVReductions(VPlan &Plan,
// If there's a header mask, the backedge select will not be the find-last
// select.
VPValue *BackedgeVal = PhiR->getBackedgeValue();
- VPValue *CondSelect = BackedgeVal;
- if (HeaderMask &&
- !match(BackedgeVal, m_Select(m_Specific(HeaderMask),
- m_VPValue(CondSelect), m_Specific(PhiR))))
+ VPValue *FindLastSelect = BackedgeVal;
+ if (HeaderMask && !match(BackedgeVal, m_Select(m_Specific(HeaderMask),
+ m_VPValue(FindLastSelect),
+ m_Specific(PhiR))))
llvm_unreachable("expected header mask select");
- // Get the IV from the conditional select of the reduction phi.
- // The conditional select should be a select between the phi and the IV.
- VPValue *Cond, *TrueVal, *FalseVal;
- if (!match(CondSelect, m_Select(m_VPValue(Cond), m_VPValue(TrueVal),
- m_VPValue(FalseVal))))
+ // The conditional select of the reduction phi should be a select between
+ // the phi and an IV-based expression. Get that expression.
+ VPValue *Cond, *FindLastExpression;
+ if (!match(FindLastSelect, m_Select(m_VPValue(Cond), m_Specific(PhiR),
+ m_VPValue(FindLastExpression))) &&
+ !match(FindLastSelect,
+ m_Select(m_VPValue(Cond), m_VPValue(FindLastExpression),
+ m_Specific(PhiR))))
continue;
- // The non-phi operand of the select is the IV.
- assert(is_contained(CondSelect->getDefiningRecipe()->operands(), PhiR));
- VPValue *IV = TrueVal == PhiR ? FalseVal : TrueVal;
-
- const SCEV *IVSCEV = vputils::getSCEVExprForVPValue(IV, PSE, &L);
+ // Check if FindLastExpression is a simple expression of a widened IV. If
+ // so, we can track the underlying IV and instead sink the expression.
----------------
ayalz wrote:
```suggestion
// so, we can track the underlying IV instead and sink the expression.
```
https://github.com/llvm/llvm-project/pull/183911
More information about the llvm-commits
mailing list