Path: blob/master/test/hotspot/jtreg/compiler/loopopts/IterationSplitPredicateInconsistency.java
41149 views
/*1* Copyright (c) 2018, 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 8193130 820391526* @summary Bad graph when unrolled loop bounds conflicts with range checks27* @requires vm.flavor == "server"28*29* @run main/othervm IterationSplitPredicateInconsistency30* @run main/othervm -XX:-UseLoopPredicate IterationSplitPredicateInconsistency31* @run main/othervm -XX:LoopStripMiningIter=0 IterationSplitPredicateInconsistency32*33*/3435public class IterationSplitPredicateInconsistency {36static volatile int barrier;3738// Pollute profile so loop appears to run for a large number of iterations39static boolean test1_helper(int start, int stop, double[] array1, double[] array2, int exit) {40for (int i = start; i < stop; i++) {41array1[i] = array2[i];42if (i == exit) {43return true;44}45barrier = 0x42;46}47return false;48}4950static double[] test1(int start, double[] array2, int exit) {51double[] array1 = new double[10];52// Predication moves range checks out of loop and53// pre/main/post loops are created. The main loop is unrolled54// several times to the point where it's never executed but55// compiler can't tell from the loop bounds alone. The lower56// bound of the loop is negative and would cause range checks57// (that were removed from the loop body) to fail.58if (test1_helper(start, 5, array1, array2, exit)) {59return null;60}61return array1;62}6364// Same as above with other combinations of increasing/decreasing65// loops, positive/negative stride66static boolean test2_helper(int start, int stop, double[] array1, double[] array2, int exit) {67for (int i = start-1; i >= stop; i--) {68array1[i] = array2[i];69if (i == exit) {70return true;71}72barrier = 0x42;73}74return false;75}7677static double[] test2(int start, double[] array2, int exit) {78double[] array1 = new double[10];79if (test2_helper(start, 0, array1, array2, exit)) {80return null;81}82return array1;83}8485static boolean test3_helper(int start, int stop, double[] array1, double[] array2, int exit) {86for (int i = start; i < stop; i++) {87array1[stop-i-1] = array2[stop-i-1];88if (i == exit) {89return true;90}91barrier = 0x42;92}93return false;94}9596static double[] test3(int start, double[] array2, int exit) {97double[] array1 = new double[5];98if (test3_helper(start, 5, array1, array2, exit)) {99return null;100}101return array1;102}103104static boolean test4_helper(int start, int stop, int from, double[] array1, double[] array2, int exit) {105for (int i = start-1; i >= stop; i--) {106array1[from-i-1] = array2[from-i-1];107if (i == exit) {108return true;109}110barrier = 0x42;111}112return false;113}114115static double[] test4(int start, double[] array2, int exit) {116double[] array1 = new double[5];117if (test4_helper(start, 0, 5, array1, array2, exit)) {118return null;119}120return array1;121}122123public static void main(String[] args) {124double[] array2 = new double[10];125double[] array3 = new double[1000];126for (int i = 0; i < 20_000; i++) {127test1_helper(0, 1000, array3, array3, 998);128test1(0, array2, 999);129test1(0, array2, 4);130test2_helper(1000, 0, array3, array3, 1);131test2(5, array2, 999);132test2(5, array2, 1);133test3_helper(0, 1000, array3, array3, 998);134test3(0, array2, 999);135test3(0, array2, 4);136test4_helper(1000, 0, 1000, array3, array3, 1);137test4(5, array2, 999);138test4(5, array2, 1);139}140}141}142143144