1 /* 2 * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package compiler.vectorapi; 25 26 import jdk.incubator.vector.ByteVector; 27 import jdk.incubator.vector.Vector; 28 import jdk.incubator.vector.VectorSpecies; 29 30 import java.util.Arrays; 31 32 import jdk.test.lib.format.ArrayDiff; 33 34 /* 35 * @test 36 * @bug 8259353 8259601 37 * @summary VectorReinterpretNode is incorrectly optimized out 38 * @modules jdk.incubator.vector 39 * @library /test/lib 40 * 41 * @run main compiler.vectorapi.Test8259353 42 */ 43 public class Test8259353 { 44 45 static final VectorSpecies<Byte> SPECIES_128 = ByteVector.SPECIES_128; 46 static final VectorSpecies<Byte> SPECIES_64 = ByteVector.SPECIES_64; 47 48 static final byte[] a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 49 static final byte[] b = new byte[16]; 50 static final byte[] c = new byte[16]; 51 static final byte[] r = {0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0}; 52 func()53 private static void func() { 54 var av = ByteVector.fromArray(SPECIES_128, a, 0); 55 var bv = (ByteVector)av.reinterpretShape(SPECIES_64, 0); 56 bv.intoArray(b, 0); 57 58 var cv = (ByteVector)bv.reinterpretShape(SPECIES_128, 0); 59 cv.intoArray(c, 0); 60 } 61 main(String[] args)62 public static void main(String[] args) { 63 for (int i = 0; i < 100000; i++) { 64 func(); 65 } 66 67 System.out.println("a: " + Arrays.toString(a)); 68 System.out.println("b: " + Arrays.toString(b)); 69 System.out.println("c: " + Arrays.toString(c)); 70 71 var diff = ArrayDiff.of(b, r); 72 if (!diff.areEqual()) { 73 throw new AssertionError("b array is unexpected: " + diff.format()); 74 } 75 76 diff = ArrayDiff.of(c, r); 77 if (!diff.areEqual()) { 78 throw new AssertionError("c array is unexpected: " + diff.format()); 79 } 80 } 81 } 82 83