Path: blob/master/test/hotspot/jtreg/compiler/rangechecks/TestBadFoldCompare.java
41152 views
/*1* Copyright (c) 2015, 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 808583226* @bug 813506927* @summary x <= 0 || x > 0 wrongly folded as (x-1) >u -1 and x < 0 || x > -1 wrongly folded as x >u -128*29* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement30* compiler.rangechecks.TestBadFoldCompare31*/3233package compiler.rangechecks;3435public class TestBadFoldCompare {3637static boolean test1_taken;3839static void helper1(int i, int a, int b, boolean flag) {40if (flag) {41if (i <= a || i > b) {42test1_taken = true;43}44}45}4647static void test1(int i, boolean flag) {48helper1(i, 0, 0, flag);49}5051static boolean test2_taken;5253static void helper2(int i, int a, int b, boolean flag) {54if (flag) {55if (i > b || i <= a) {56test2_taken = true;57}58}59}6061static void test2(int i, boolean flag) {62helper2(i, 0, 0, flag);63}6465static boolean test3_taken;6667static void helper3(int i, int a, int b, boolean flag) {68if (flag) {69if (i < a || i > b - 1) {70test3_taken = true;71}72}73}7475static void test3(int i, boolean flag) {76helper3(i, 0, 0, flag);77}7879static boolean test4_taken;8081static void helper4(int i, int a, int b, boolean flag) {82if (flag) {83if (i > b - 1 || i < a) {84test4_taken = true;85}86}87}8889static void test4(int i, boolean flag) {90helper4(i, 0, 0, flag);91}9293static public void main(String[] args) {94boolean success = true;9596for (int i = 0; i < 20000; i++) {97helper1(5, 0, 10, (i%2)==0);98helper1(-1, 0, 10, (i%2)==0);99helper1(15, 0, 10, (i%2)==0);100test1(0, false);101}102test1_taken = false;103test1(0, true);104if (!test1_taken) {105System.out.println("Test1 failed");106success = false;107}108109for (int i = 0; i < 20000; i++) {110helper2(5, 0, 10, (i%2)==0);111helper2(-1, 0, 10, (i%2)==0);112helper2(15, 0, 10, (i%2)==0);113test2(0, false);114}115test2_taken = false;116test2(0, true);117118if (!test2_taken) {119System.out.println("Test2 failed");120success = false;121}122123for (int i = 0; i < 20000; i++) {124helper3(5, 0, 10, (i%2)==0);125helper3(-1, 0, 10, (i%2)==0);126helper3(15, 0, 10, (i%2)==0);127test3(0, false);128}129test3_taken = false;130test3(0, true);131132if (!test3_taken) {133System.out.println("Test3 failed");134success = false;135}136137for (int i = 0; i < 20000; i++) {138helper4(5, 0, 10, (i%2)==0);139helper4(-1, 0, 10, (i%2)==0);140helper4(15, 0, 10, (i%2)==0);141test4(0, false);142}143test4_taken = false;144test4(0, true);145146if (!test4_taken) {147System.out.println("Test4 failed");148success = false;149}150151if (!success) {152throw new RuntimeException("Some tests failed");153}154}155}156157158