Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8259775

[Vector API] Incorrect code-gen for VectorReinterpret operation

XMLWordPrintable

    • b34
    • Verified

        This reproducer generates wrong results on x86.
        ```
        import jdk.incubator.vector.ByteVector;
        import jdk.incubator.vector.VectorSpecies;

        import java.util.Arrays;

        public class Test {

                static final VectorSpecies<Byte> SPECIES_256 = ByteVector.SPECIES_256;
                static final VectorSpecies<Byte> SPECIES_128 = ByteVector.SPECIES_128;

                static byte[] a = new byte[32];
                static byte[] b = new byte[32];

                private static void func() {
                        ByteVector av = ByteVector.fromArray(SPECIES_256, a, 0);
                        ByteVector bv = (ByteVector)av.reinterpretShape(SPECIES_128, 0).reinterpretShape(SPECIES_256, 0);
                        bv.intoArray(b, 0);
                }

                public static void main(String[] args) {
                        for (int i = 0; i < a.length; i++) {
                            a[i] = (byte)i;
                        }
                        for (int i = 0; i < 100000; i++) {
                                func();
                        }
                        System.out.println("a: " + Arrays.toString(a));
                        System.out.println("b: " + Arrays.toString(b));
                }
        }
        ```

        Output:
        ```
        a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
        b: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
        ```

        Expected:
        ```
        a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
        b: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ```

              jiefu Jie Fu
              jiefu Jie Fu
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: