author | iignatyev |
Mon, 18 Feb 2019 09:31:07 -0800 | |
changeset 53791 | bec6c8739833 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
31132 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 8085832 |
|
32732
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
27 |
* @bug 8135069 |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
28 |
* @summary x <= 0 || x > 0 wrongly folded as (x-1) >u -1 and x < 0 || x > -1 wrongly folded as x >u -1 |
40059 | 29 |
* |
30 |
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement |
|
31 |
* compiler.rangechecks.TestBadFoldCompare |
|
31132 | 32 |
*/ |
33 |
||
40059 | 34 |
package compiler.rangechecks; |
35 |
||
31132 | 36 |
public class TestBadFoldCompare { |
37 |
||
38 |
static boolean test1_taken; |
|
39 |
||
40 |
static void helper1(int i, int a, int b, boolean flag) { |
|
41 |
if (flag) { |
|
42 |
if (i <= a || i > b) { |
|
43 |
test1_taken = true; |
|
44 |
} |
|
45 |
} |
|
46 |
} |
|
47 |
||
48 |
static void test1(int i, boolean flag) { |
|
49 |
helper1(i, 0, 0, flag); |
|
50 |
} |
|
51 |
||
52 |
static boolean test2_taken; |
|
53 |
||
54 |
static void helper2(int i, int a, int b, boolean flag) { |
|
55 |
if (flag) { |
|
56 |
if (i > b || i <= a) { |
|
57 |
test2_taken = true; |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
static void test2(int i, boolean flag) { |
|
63 |
helper2(i, 0, 0, flag); |
|
64 |
} |
|
65 |
||
32732
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
66 |
static boolean test3_taken; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
67 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
68 |
static void helper3(int i, int a, int b, boolean flag) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
69 |
if (flag) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
70 |
if (i < a || i > b - 1) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
71 |
test3_taken = true; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
72 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
73 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
74 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
75 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
76 |
static void test3(int i, boolean flag) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
77 |
helper3(i, 0, 0, flag); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
78 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
79 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
80 |
static boolean test4_taken; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
81 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
82 |
static void helper4(int i, int a, int b, boolean flag) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
83 |
if (flag) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
84 |
if (i > b - 1 || i < a) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
85 |
test4_taken = true; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
86 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
87 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
88 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
89 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
90 |
static void test4(int i, boolean flag) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
91 |
helper4(i, 0, 0, flag); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
92 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
93 |
|
31132 | 94 |
static public void main(String[] args) { |
95 |
boolean success = true; |
|
96 |
||
97 |
for (int i = 0; i < 20000; i++) { |
|
98 |
helper1(5, 0, 10, (i%2)==0); |
|
99 |
helper1(-1, 0, 10, (i%2)==0); |
|
100 |
helper1(15, 0, 10, (i%2)==0); |
|
101 |
test1(0, false); |
|
102 |
} |
|
103 |
test1_taken = false; |
|
104 |
test1(0, true); |
|
105 |
if (!test1_taken) { |
|
106 |
System.out.println("Test1 failed"); |
|
107 |
success = false; |
|
108 |
} |
|
109 |
||
110 |
for (int i = 0; i < 20000; i++) { |
|
111 |
helper2(5, 0, 10, (i%2)==0); |
|
112 |
helper2(-1, 0, 10, (i%2)==0); |
|
113 |
helper2(15, 0, 10, (i%2)==0); |
|
114 |
test2(0, false); |
|
115 |
} |
|
116 |
test2_taken = false; |
|
117 |
test2(0, true); |
|
118 |
||
119 |
if (!test2_taken) { |
|
120 |
System.out.println("Test2 failed"); |
|
121 |
success = false; |
|
122 |
} |
|
32732
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
123 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
124 |
for (int i = 0; i < 20000; i++) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
125 |
helper3(5, 0, 10, (i%2)==0); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
126 |
helper3(-1, 0, 10, (i%2)==0); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
127 |
helper3(15, 0, 10, (i%2)==0); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
128 |
test3(0, false); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
129 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
130 |
test3_taken = false; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
131 |
test3(0, true); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
132 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
133 |
if (!test3_taken) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
134 |
System.out.println("Test3 failed"); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
135 |
success = false; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
136 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
137 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
138 |
for (int i = 0; i < 20000; i++) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
139 |
helper4(5, 0, 10, (i%2)==0); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
140 |
helper4(-1, 0, 10, (i%2)==0); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
141 |
helper4(15, 0, 10, (i%2)==0); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
142 |
test4(0, false); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
143 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
144 |
test4_taken = false; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
145 |
test4(0, true); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
146 |
|
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
147 |
if (!test4_taken) { |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
148 |
System.out.println("Test4 failed"); |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
149 |
success = false; |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
150 |
} |
9f4cf1523072
8135069: C2 replaces range checks by unsigned comparison with -1
roland
parents:
31132
diff
changeset
|
151 |
|
31132 | 152 |
if (!success) { |
153 |
throw new RuntimeException("Some tests failed"); |
|
154 |
} |
|
155 |
} |
|
156 |
} |