Path: blob/master/test/hotspot/jtreg/compiler/loopstripmining/TestEliminatedLoadPinnedOnBackedge.java
41149 views
/*1* Copyright (c) 2020, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 825757526* @summary C2: "failed: only phis" assert failure in loop strip mining verfication27*28* @run main/othervm -XX:LoopUnrollLimit=0 -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:CompileCommand=dontinline,TestEliminatedLoadPinnedOnBackedge::notInlined29* -XX:CompileCommand=inline,TestEliminatedLoadPinnedOnBackedge::inlined TestEliminatedLoadPinnedOnBackedge30*31*/3233public class TestEliminatedLoadPinnedOnBackedge {34private static Object field2;3536final static int iters = 2000;3738public static void main(String[] args) {39boolean[] flags = new boolean[iters];40for (int i = 0; i < iters; i++) {41flags[i] = i < iters/2;42}43for (int i = 0; i < 20_000; i++) {44test1(flags);45test2(flags, 1);46test3(flags);47inlined(new Object(), 1);48inlined(new Object(), 4);49inlined2(42);50inlined2(0x42);51}52}5354static int field;5556private static int test1(boolean[] flags) {57int k = 2;58for (; k < 4; k *= 2) {59}60int[] array = new int[10];61notInlined(array);62// This load commons with the load on the backedge after the63// outer strip mined loop is expanded.64int v = array[0];65array[1] = 42;66// No use for o. Allocation removed at macro expansion time.67Object o = new Object();68inlined(o, k);69int i = 0;70for (; ; ) {71synchronized (array) {72}73if (i >= iters) {74break;75}76v = array[0]; // This load ends up on the backedge77if (flags[i]) {78inlined2(array[1]);79}80i++;81}82return v;83}8485private static int test2(boolean[] flags, int d) {86int k = 2;87for (; k < 4; k *= 2) {88}89int[] array = new int[10];90notInlined(array);91int v = array[0];92array[1] = 42;93Object o = new Object();94inlined(o, k);95int i = 0;96for (; ; ) {97synchronized (array) {98}99if (d == 0) {}100if (i >= iters) {101break;102}103v = (array[0] + array[2]) / d;104if (flags[i]) {105inlined2(array[1]);106}107i++;108}109return v;110}111112private static int test3(boolean[] flags) {113int k = 2;114for (; k < 4; k *= 2) {115}116int[] array = new int[10];117notInlined(array);118int v1 = array[0];119int v2 = array[2];120array[1] = 42;121Object o = new Object();122inlined(o, k);123int i = 0;124for (; ; ) {125synchronized (array) {126}127if (i >= iters) {128break;129}130v1 = array[0];131v2 = array[2];132if (flags[i]) {133inlined2(array[1]);134}135i++;136}137return v1 + v2;138}139140private static void inlined2(int i) {141if (i != 42) {142field = 42;143}144}145146private static void inlined(Object o, int i) {147if (i != 4) {148field2 = o;149}150}151152private static void notInlined(int[] array) {153java.util.Arrays.fill(array, 1);154}155}156157158