[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


================
@@ -5710,11 +5746,17 @@ void VPlanTransforms::optimizeFindIVReductions(VPlan &Plan,
                                     m_VPValue(FalseVal))))
       continue;
 
-    // The non-phi operand of the select is the IV.
-    assert(is_contained(CondSelect->getDefiningRecipe()->operands(), PhiR));
+    // The non-phi operand of the select is the IV (or expression of IV).
+    assert(is_contained(BackedgeVal->getDefiningRecipe()->operands(), PhiR));
     VPValue *IV = TrueVal == PhiR ? FalseVal : TrueVal;
 
-    const SCEV *IVSCEV = vputils::getSCEVExprForVPValue(IV, PSE, &L);
+    // Check if IV is a simple expression of a widened IV.
+    // If so, we can track the underlying IV and sink the expression.
+    VPWidenIntOrFpInductionRecipe *ExpressionIV =
+        getExpressionIV(IV, VectorLoopRegion);
+    VPValue *IVToTrack = ExpressionIV ? ExpressionIV : IV;
----------------
fhahn wrote:

We need to track both the original ExprOfIV and ExpressionIV, renamed to clarify, thanks

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


More information about the llvm-commits mailing list