[llvm] [VPlan] Optimize FindLast of (binop %IV, live-in) by sinking. (PR #183911)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 21 05:36:05 PDT 2026
================
@@ -5783,16 +5823,34 @@ void VPlanTransforms::optimizeFindIVReductions(VPlan &Plan,
BackedgeVal,
match_fn(m_VPInstruction<VPInstruction::ComputeReductionResult>())));
+ // If IV is an expression, create a new select that tracks the underlying
+ // IV directly and update the backedge value.
+ if (ExpressionIV) {
+ auto *SelectR = CondSelect->getDefiningRecipe();
+ VPBuilder LoopBuilder(SelectR);
+ VPValue *SelectCond = Cond;
+ if (TrueVal == PhiR)
+ SelectCond = LoopBuilder.createNot(Cond);
+ CondSelect = LoopBuilder.createSelect(SelectCond, ExpressionIV, PhiR,
+ SelectR->getDebugLoc());
----------------
ayalz wrote:
Having both `CondSelect` and `SelectCond` may be confusing. Could `CondSelect` be better renamed, independently, `ReducingSelect` or `FindLastSelect` (it's only last we're after here, right?). Suggest to use `Cond` instead of `SelectCond` - retrieving it and TrueVal here than carry them over, can retain order of operands than reverse the condition:
```suggestion
auto DL = SelectR->getDebugLoc();
VPValue *Cond = SelectR->getOperand(0);
if (SelectR->getOperand(1) == PhiR)
CondSelect = LoopBuilder.createSelect(Cond, PhiR, ExpressionIV, DL);
else
CondSelect = LoopBuilder.createSelect(Cond, ExpressionIV, PhiR, DL);
```
https://github.com/llvm/llvm-project/pull/183911
More information about the llvm-commits
mailing list