[llvm] [LV] Support argmin/argmax with strict predicates. (PR #170223)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 2 14:30:20 PST 2025
================
@@ -310,6 +311,11 @@ class RecurrenceDescriptor {
isFindLastIVRecurrenceKind(Kind);
}
+ /// Returns true if \p AR's range is valid for either FindFirstIV or
+ /// FindLastIV reductions i.e. if the sentinel value is outside \p AR's range.
----------------
ayalz wrote:
The sentinel value should be outside AR's range, when FindFirstIV or FindLastIV work with a condition that may be false for all values inside AR's range, as in that case the out-of-bound sentinel value helps to convey that answer. But for argmin/argmax with strict/FirstIV or non-strict/LastIV, the condition is guaranteed to be true at-least once inside AR's range. So having a sentinel inside AR's range should be fine?
Follow-up thought: even if the condition may be false for all values inside AR's range, but the final value to return in that case coincides with the natural sentinel inside AR's range, it could potentially also be optimized as above. E.g., suppose FindLastIV work with an arbitrary condition a[i]>0 in the range [0,100], where if all a's are zeroes the value to return is 0.
Another thought: argmin/argmax is interesting not only because it's condition is guaranteed to hold at-least once in the range, but also because it supports FindFirstIV naturally (w/o negating the IV - which conceptually still means it's a FindLastIV but on a decreasing derived IV) - by relying on the running min/max recurrence whose strict comparison precludes repeated occurrences. This relates to a discussion we had on some earlier patch, where adding another, dependent (boolean "found") recurrence was found to have significant negative impact.
https://github.com/llvm/llvm-project/pull/170223
More information about the llvm-commits
mailing list