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

Emanuel Peter epeter at openjdk.org
Fri May 12 07:26:51 UTC 2023


On Fri, 12 May 2023 06:57:41 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Note: If I have uses of the reduction in each iteration, then we already refuse to vectorize the reduction, as in this case:
>> 
>>     static int test(int[] data, int sum) {
>>         int x = 0;
>>         for (int i = 0; i < RANGE; i++) {
>>             sum += 11 * data[i];
>>             x += sum & i;  // vector use of sum prevents vectorization of sum's reduction-vectorization -> whole chain not vectorized
>>         }
>>         return sum + x;
>>     }
>
> My conclusion, given my best understanding: eigher we have a use of the `sum` in all iterations, which prevents vectorization of the reduction. Or we only have a use of the last iteration, and it drops out of the loop already.
> 
> So if there is such an odd example, I'd rather we run into an assert in debug and look at it again. Maybe it would be perfectly legal, or maybe it reveals a bug here or elsewhere in the reduction code.
> 
> @sviswa7 what do you think?

Ah, but this hits one of my asserts:

    static int test(int[] data, int sum) {
        int x = 0;
        for (int i = 0; i < RANGE; i+=8) {
            sum += 11 * data[i+0];
            sum += 11 * data[i+1];
            sum += 11 * data[i+2];
            sum += 11 * data[i+3];
            x = sum + i;
            sum += 11 * data[i+4];
            sum += 11 * data[i+5];
            sum += 11 * data[i+6];
            sum += 11 * data[i+7];
        }
        return sum + x;
    }

With

./java -Xbatch -XX:CompileCommand=compileonly,Test::test -XX:+TraceNewVectors -XX:+TraceSuperWord -XX:MaxVectorSize=16 Test.java


Triggers
https://github.com/openjdk/jdk/blob/31d977c21f7a2b62fb8123bc7967731aa961e373/src/hotspot/share/opto/loopopts.cpp#L4217

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

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


More information about the hotspot-compiler-dev mailing list