RFR: 8302652: [SuperWord] Reduction should happen after loop, when possible [v5]

Sandhya Viswanathan sviswanathan at openjdk.org
Fri May 12 21:52:53 UTC 2023


On Fri, 12 May 2023 07:38:42 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> src/hotspot/share/opto/loopopts.cpp line 4210:
>> 
>>> 4208:           if (use != phi && ctrl_or_self(use) == cl) {
>>> 4209:             DEBUG_ONLY( current->dump(-1); )
>>> 4210:             assert(false, "reduction has use inside loop");
>> 
>> I have been wondering, it is right to bailout here from the optimization but why do we assert here? It is perfectly legal (if not very meaningful) to have a scalar use of the last unordered reduction within the loop. This will still auto vectorize as the reduction is to a scalar. e.g. a slight modification of the SumRed_Int.java still auto vectorizes and has a use of the last unordered reduction within the loop: 
>>    public static int sumReductionImplement(
>>             int[] a,
>>             int[] b,
>>             int[] c,
>>             int total) {
>>         int sum = 0;
>>         for (int i = 0; i < a.length; i++) {
>>             total += (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
>>             sum = total + i;
>>         }
>>         return total + sum;
>>     }
>> Do you think this is a valid concern?
>
> I will add this as a regression test, and remove that assert. Thanks @sviswa7 for making me look at this more closely :)
> 
> Still, I think it may be valuable to keep these two asserts - both indicate that something strange has happened:
> 
> https://github.com/openjdk/jdk/blob/31d977c21f7a2b62fb8123bc7967731aa961e373/src/hotspot/share/opto/loopopts.cpp#L4210
> 
> https://github.com/openjdk/jdk/blob/31d977c21f7a2b62fb8123bc7967731aa961e373/src/hotspot/share/opto/loopopts.cpp#L4199

Sounds good to me.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13056#discussion_r1192820468


More information about the hotspot-compiler-dev mailing list