[llvm] [LV] Support argmin/argmax with strict predicates. (PR #170223)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 23 07:24:50 PST 2025


================
@@ -1120,6 +1122,128 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
   return true;
 }
 
+/// For argmin/argmax reductions with strict predicates, convert the existing
+/// FindLastIV reduction to a new UMin reduction of a wide canonical IV. If the
+/// original IV was not canonical, a new canonical wide IV is added, and the
+/// final result is scaled back to the original IV.
+static bool handleFirstArgMinArgMax(VPlan &Plan,
+                                    VPReductionPHIRecipe *MinMaxPhiR,
+                                    VPReductionPHIRecipe *FindIVPhiR,
+                                    VPWidenIntOrFpInductionRecipe *WideIV,
+                                    VPInstruction *MinMaxResult) {
+  Type *Ty = Plan.getVectorLoopRegion()->getCanonicalIVType();
+  // TODO: Support different IV types.
+  if (Ty != VPTypeAnalysis(Plan).inferScalarType(FindIVPhiR))
----------------
ayalz wrote:

```suggestion
  if (Ty != VPTypeAnalysis(Plan).inferScalarType(WideIV))
```
FindIVPhiR and WideIV should have the same scalar type (worth asserting?), but it's the latter that gets replaced by a WideCanIV if (type is but start/step are) not canonical.

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


More information about the llvm-commits mailing list