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

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 05:26:52 PST 2025


================
@@ -992,3 +992,92 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
   MiddleTerm->setOperand(0, NewCond);
   return true;
 }
+
+bool VPlanTransforms::handleMultiUseReductions(VPlan &Plan) {
+  for (auto &PhiR : make_early_inc_range(
+           Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis())) {
+    auto *MinMaxPhiR = dyn_cast<VPReductionPHIRecipe>(&PhiR);
+    if (!MinMaxPhiR)
+      continue;
+
+    RecurKind RdxKind = MinMaxPhiR->getRecurrenceKind();
+    // TODO: check for multi-uses in VPlan directly.
+    if (!MinMaxPhiR->hasLoopUsesOutsideReductionChain())
+      continue;
----------------
ayalz wrote:

```suggestion
    // TODO: check for multi-uses in VPlan directly.
    if (!MinMaxPhiR || !MinMaxPhiR->hasLoopUsesOutsideReductionChain())
      continue;

    RecurKind RdxKind = MinMaxPhiR->getRecurrenceKind();
```

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


More information about the llvm-commits mailing list