Path: blob/master/test/hotspot/jtreg/compiler/rangechecks/TestRangeCheckLimits.java
64478 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. 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 826201726* @summary Dominator failure because ConvL2I node becomes TOP due to missing overflow/underflow handling in range check elimination27* in PhaseIdealLoop::add_constraint().28* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileCommand=compileonly,compiler.rangechecks.TestRangeCheckLimits::*29* compiler.rangechecks.TestRangeCheckLimits30*/3132package compiler.rangechecks;3334public class TestRangeCheckLimits {35static int a = 400;36static volatile int b;37static long lFld;38static int iFld;3940public static void main(String[] k) {41// Test all cases in PhaseIdealLoop::add_constraint().42testPositiveCaseMainLoop();43testNegativeCaseMainLoop();44testPositiveCasePreLoop();45testNegativeCasePreLoop();46}4748public static void testPositiveCaseMainLoop() {49int e, f, g = 0, h[] = new int[a];50double i[] = new double[a];51long j = 9;52Helper.init(h, 3);53for (e = 5; e < 154; e++) {54for (f = 1; f < 169; f += 2) {55b = e;56}57i[1] = b;58for (g = 8; g < 168; g += 2) {59j = g - 5;60if (j > Integer.MAX_VALUE - 1) {61switch (3) {62case 3:63}64}65}66}67if (g != 168) {68throw new RuntimeException("fail");69}70lFld = j;71}727374public static void testPositiveCasePreLoop() {75int e, f, g = 0, h[] = new int[a];76double i[] = new double[a];77long j = 9;78Helper.init(h, 3);79for (e = 5; e < 154; e++) {80for (f = 1; f < 169; f += 2) {81b = e;82}83i[1] = b;84for (g = 8; g < 168; g += 2) {85j = g + 5;86if (j > 180) {87switch (3) {88case 3:89}90}91}92}93if (g != 168) {94throw new RuntimeException("fail");95}96lFld = j;97}9899public static void testNegativeCaseMainLoop() {100int e, f, g = 0, h[] = new int[a];101double i[] = new double[a];102long j = 9;103Helper.init(h, 3);104for (e = 5; e < 154; e++) {105for (f = 1; f < 169; f += 2) {106b = e;107}108i[1] = b;109for (g = 8; g < 168; g += 2) {110j = g;111if (j < 5) {112switch (3) {113case 3:114}115}116}117}118if (g != 168) {119throw new RuntimeException("fail");120}121lFld = j;122}123124125public static void testNegativeCasePreLoop() {126int e, f, g = 0, h[] = new int[a];127double i[] = new double[a];128long j = 9;129Helper.init(h, 3);130for (e = 5; e < 154; e++) {131for (f = 1; f < 169; f += 2) {132b = e;133}134i[1] = b;135for (g = 168; g > 8; g -= 2) {136j = g - 5;137if (j > Integer.MAX_VALUE - 1) {138switch (3) {139case 3:140}141}142}143}144if (g != 8) {145throw new RuntimeException("fail");146}147lFld = j;148}149}150151class Helper {152public static void init(int[] a, int seed) {153for (int j = 0; j < a.length; j++) {154a[j] = (j % 2 == 0) ? seed + j : seed - j;155}156}157}158159160