1 /* 2 * Copyright (c) 2014, 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 26 * @bug 8048170 27 * @summary Following range check smearing, range check cannot be replaced by dominating identical test. 28 * 29 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement 30 * compiler.rangechecks.TestRangeCheckSmearingLoopOpts 31 */ 32 33 package compiler.rangechecks; 34 35 public class TestRangeCheckSmearingLoopOpts { 36 37 static int dummy; 38 39 static int m1(int[] array, int i) { 40 for (;;) { 41 for (;;) { 42 if (array[i] < 0) { // range check (i+0) dominates equivalent check below 43 break; 44 } 45 i++; 46 } 47 48 // A control flow that stops IfNode::up_one_dom() 49 if ((i % 2)== 0) { 50 if ((array[i] % 2) == 0) { 51 dummy = i; 52 } 53 } 54 55 // IfNode::Ideal will rewrite some range checks if Compile::allow_range_check_smearing 56 if (array[i-1] == 9) { // range check (i-1) unchanged 57 int res = array[i-3]; // range check (i-3) unchanged 58 res += array[i]; // range check (i+0) unchanged 59 res += array[i-2]; // removed redundant range check 60 // the previous access might be hoisted by 61 // PhaseIdealLoop::split_if_with_blocks_post because 62 // it appears to have the same guard, but it also 63 // depends on the previous guards 64 return res; 65 } 66 i++; 67 } 68 } 69 70 static public void main(String[] args) { 71 int[] array = { 0, 1, 2, -3, 4, 5, -2, 7, 8, 9, -1 }; 72 for (int i = 0; i < 20000; i++) { 73 m1(array, 0); 74 } 75 array[0] = -1; 76 try { 77 m1(array, 0); 78 } catch(ArrayIndexOutOfBoundsException aioobe) {} 79 } 80 }