|
| 1 | +/* |
| 2 | + * Copyright (c) 2026, 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 | +/* |
| 25 | + * @test id=all-flags |
| 26 | + * @summary Test a case where we can have one memory slice that has only loads, |
| 27 | + * but the loads from the slice do not have all the same input memory |
| 28 | + * state from before the loop. This is rather rare but it can happen. |
| 29 | + * @bug 8373453 |
| 30 | + * @run main/othervm |
| 31 | + * -XX:CompileCommand=compileonly,${test.main.class}::test |
| 32 | + * -Xbatch -XX:-TieredCompilation |
| 33 | + * ${test.main.class} |
| 34 | + */ |
| 35 | + |
| 36 | +/* |
| 37 | + * @test id=fewer-flags |
| 38 | + * @bug 8373453 |
| 39 | + * @run main/othervm |
| 40 | + * -XX:CompileCommand=compileonly,${test.main.class}::test |
| 41 | + * ${test.main.class} |
| 42 | + */ |
| 43 | + |
| 44 | +/* |
| 45 | + * @test id=vanilla |
| 46 | + * @bug 8373453 |
| 47 | + * @run main ${test.main.class} |
| 48 | + */ |
| 49 | + |
| 50 | +package compiler.loopopts.superword; |
| 51 | + |
| 52 | +public class TestLoadSliceWithMultipleMemoryInputStates { |
| 53 | + static void test() { |
| 54 | + // The relevant slice is the value field of the Byte Objects. |
| 55 | + Byte x = 1; |
| 56 | + |
| 57 | + for (int i = 0; i < 2; i++) { |
| 58 | + if ((i & 1) == 0) { |
| 59 | + // Not sure what this loop is needed for, but it is very sensitive, |
| 60 | + // I cannot even replace N with 32. |
| 61 | + int N = 32; |
| 62 | + for (int j = 0; j < N; j++) { |
| 63 | + if (j == 1) { |
| 64 | + x = (byte) x; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + for (int j = 0; j < 32; j++) { |
| 69 | + // The call below has an effect on the memory state |
| 70 | + // If we optimize the Load for Byte::value, we can bypass |
| 71 | + // this call, since we know that Byte::value cannot be |
| 72 | + // modified during the call. |
| 73 | + Object o = 1; |
| 74 | + o.toString(); |
| 75 | + |
| 76 | + for (int k = 0; k < 32; k++) { // OSR around here |
| 77 | + // Loads of x byte field have different memory input states |
| 78 | + // This is because some loads can split their memory state |
| 79 | + // through a phi further up, and others are not put back on |
| 80 | + // the IGVN worklist and are thus not optimized and keep |
| 81 | + // the old memory state. Both are correct though. |
| 82 | + x = (byte) (x + 1); |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + public static void main(String[] args) { |
| 90 | + for (int i = 0; i < 10_000; i++) { |
| 91 | + test(); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments