[llvm] [LV] Vectorize selecting last IV of min/max element. (PR #141431)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 18 06:16:53 PST 2025


================
@@ -8162,13 +8174,19 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
           getScalingForReduction(RdxDesc.getLoopExitInstr()).value_or(1);
       PhiRecipe = new VPReductionPHIRecipe(
           Phi, RdxDesc.getRecurrenceKind(), *StartV, CM.isInLoopReduction(Phi),
-          CM.useOrderedReductions(RdxDesc), ScaleFactor);
-    } else {
+          CM.useOrderedReductions(RdxDesc), ScaleFactor,
+          RdxDesc.isPhiMultiUse());
+    } else if (Legal->isFixedOrderRecurrence(Phi)) {
       // TODO: Currently fixed-order recurrences are modeled as chains of
       // first-order recurrences. If there are no users of the intermediate
       // recurrences in the chain, the fixed order recurrence should be modeled
       // directly, enabling more efficient codegen.
       PhiRecipe = new VPFirstOrderRecurrencePHIRecipe(Phi, *StartV);
+    } else {
+      // Failed to identify phi as reduction or fixed-order recurrence. Keep the
+      // original VPWidenPHIRecipe for now, to be legalized later if possible.
+      setRecipe(Phi, R);
+      return nullptr;
----------------
Mel-Chen wrote:

I think we don't need this, right?

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


More information about the llvm-commits mailing list