--- /dev/null 2015-04-28 16:14:11.867039931 +0200 +++ new/test/compiler/rangechecks/TestBadFoldCompare.java 2015-06-08 17:25:24.152010219 +0200 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8085832 + * @summary x <= 0 || x > 0 wrongly folded as (x-1) >u -1 + * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestBadFoldCompare + */ + +public class TestBadFoldCompare { + + static boolean test1_taken; + + static void helper1(int i, int a, int b, boolean flag) { + if (flag) { + if (i <= a || i > b) { + test1_taken = true; + } + } + } + + static void test1(int i, boolean flag) { + helper1(i, 0, 0, flag); + } + + static boolean test2_taken; + + static void helper2(int i, int a, int b, boolean flag) { + if (flag) { + if (i > b || i <= a) { + test2_taken = true; + } + } + } + + static void test2(int i, boolean flag) { + helper2(i, 0, 0, flag); + } + + static public void main(String[] args) { + boolean success = true; + + for (int i = 0; i < 20000; i++) { + helper1(5, 0, 10, (i%2)==0); + helper1(-1, 0, 10, (i%2)==0); + helper1(15, 0, 10, (i%2)==0); + test1(0, false); + } + test1_taken = false; + test1(0, true); + if (!test1_taken) { + System.out.println("Test1 failed"); + success = false; + } + + for (int i = 0; i < 20000; i++) { + helper2(5, 0, 10, (i%2)==0); + helper2(-1, 0, 10, (i%2)==0); + helper2(15, 0, 10, (i%2)==0); + test2(0, false); + } + test2_taken = false; + test2(0, true); + + if (!test2_taken) { + System.out.println("Test2 failed"); + success = false; + } + if (!success) { + throw new RuntimeException("Some tests failed"); + } + } +}