[flang-commits] [flang] [flang] Fetch the initial reduction value from the input array. (PR #136790)

via flang-commits flang-commits at lists.llvm.org
Wed Apr 23 05:51:00 PDT 2025


https://github.com/jeanPerier commented:

Naïve question: why is a first element needed for numerical min/max val/loc?

Isn't there a comparison + iteration order that could be used so that the type representation min/max can be used as a starting point instead of some value from the input array?

For instance, assuming MAXLOC with BACK being absent, we could start with zero coordinates and a temporary max being the numerical min for that type, then the array could be iterated backwards (maybe that is a bad idea from a memory access perspective though)  always replacing the result when something bigger or equal is found. Then there is no need to deal with the array size and mask.

Again, this is a naïve question, it may be a terrible idea from a performance perspective and just be incorrect with some corner cases (nans probably? although I think `fcmp uge` would work in my example to select the first NaN in array order as being the result location (assuming that is what we want)).

Otherwise, the implementation of your solution looks good to me.

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


More information about the flang-commits mailing list