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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 24 05:47:11 PST 2026


================
@@ -1120,6 +1122,133 @@ 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
----------------
ayalz wrote:

Perhaps worth documenting somewhere (in addReductionResultComputation(), which sets Min/Max for ComputeReductionResult of FindLast/FindFirst, with a reminder here), to help clarify how UMin applies to FindLastIV, something like the following: "When the MinOrMax value occurs multiple times, finding the first occurrence corresponds to having a strict comparison for updating the running MinOrMax, whereas finding the last occurrence corresponds to having a non-strict comparison. In both cases, the iteration when this condition was last true is the desired result, which corresponds to a FindLastIV reduction. When reducing the vector of partial MinOrMax's after the loop, if the same MinOrMax occurs multiple times, the first occurrence (i.e., strict comparison) is found using a UMin reduction of the associated IV's, and the last occurrence (i.e., non-strict comparison) can be found using UMax."

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


More information about the llvm-commits mailing list