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