[llvm] [VPlan] Optimize FindLast of (binop %IV, live-in) by sinking. (PR #183911)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 15:13:02 PST 2026


================
@@ -5751,16 +5793,26 @@ void VPlanTransforms::optimizeFindIVReductions(VPlan &Plan,
         BackedgeVal,
         match_fn(m_VPInstruction<VPInstruction::ComputeReductionResult>())));
 
+    VPValue *NewBackedgeVal = CondSelect;
+    // If IV is an expression, create a new select that tracks the underlying
+    // IV directly and update the backedge value.
+    if (ExpressionIV) {
+      auto *SelectR = BackedgeVal->getDefiningRecipe();
+      VPBuilder LoopBuilder(SelectR);
+      NewBackedgeVal = LoopBuilder.createSelect(Cond, ExpressionIV, PhiR,
----------------
fhahn wrote:

Yep, thought we already negated it earlier if needed, but that's not the case; updated there, thanks!

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


More information about the llvm-commits mailing list