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

Emanuel Peter epeter at openjdk.org
Fri May 12 07:41:52 UTC 2023


On Fri, 12 May 2023 01:10:29 GMT, Sandhya Viswanathan <sviswanathan at openjdk.org> wrote:

>> Emanuel Peter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   use is_counted and is_innermost
>
> 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

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

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


More information about the hotspot-compiler-dev mailing list