RFR: 8298935: fix cyclic dependency bug in create_pack logic in SuperWord::find_adjacent_refs

Emanuel Peter epeter at openjdk.org
Fri Feb 17 10:10:20 UTC 2023


On Fri, 17 Feb 2023 07:54:00 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

> Couldn't this lead to cases where vmIntrinsics::_forEachRemaining is not vectorized anymore on these platforms although it would be legal?

@TobiHartmann You may be right. I have a test we can run on such machines. Sadly I do not have access to one myself.

If my understanding is right, this test should lead to wrong results on machines that do not allow unaligned memory access.

`./java -XX:-TieredCompilation -Xbatch -XX:CompileCommand=compileonly,*::forEachRemaining -XX:+TraceSuperWord -XX:+AlignVector Test.java`

This still vectorizes for `forEachRemaining`, even though I put the `-XX:+AlignVector` constraint in. I wonder if that happens too on machines that require vector alignment?

Because this example has an access like this `data[i] = data[i + 2]`. Assuming we vectorize and have at least 4 elements in a vector: The vector length with 4 floats would be 16 bytes. The `LoadF` and the `StoreF` are off by 2 elements, so 8 bytes. So they do not align with each other, and at most one of the two can be 16 byte aligned with memory in general.

My fix would disallow that.


import java.util.stream.IntStream;

public class Test {
    static int N = 100;

    public static void main(String[] strArr) {
        float[] data0 = new float[N];
        float[] data1 = new float[N];
        for (int i = 0; i < 10_000; i++){
            init(data0);
            init(data1);
            test(data0);
            reference(data1);
            verify(data0, data1);
        }
    }

    static void reference(float[] data) {
        for (int i = 0; i < N - 2; i++) {
            data[i] = data[i + 2];
        }
    }

    static void test(float[] data) {
        IntStream.range(0, N - 2).forEach(i -> {
            data[i] = data[i + 2];
        });
    }

    static void init(float[] data) {
        for (int j = 0; j < N; j++) {
            data[j] = j;
        }
    }

    static void verify(float[] data, float[] gold) {
        for (int i = 0; i < N; i++) {
            if (data[i] != gold[i]) {
                throw new RuntimeException(" Invalid result: dataF[" + i + "]: " + data[i] + " != " + gold[i]);
            }
        }
    }
}

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

PR: https://git.openjdk.org/jdk/pull/12350


More information about the hotspot-compiler-dev mailing list