54084
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
54084
|
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 |
package org.graalvm.compiler.jtt.optimize;
|
|
26 |
|
|
27 |
import static org.junit.runners.Parameterized.Parameter;
|
|
28 |
import static org.junit.runners.Parameterized.Parameters;
|
|
29 |
|
|
30 |
import java.lang.reflect.Method;
|
|
31 |
import java.lang.reflect.Modifier;
|
|
32 |
import java.util.ArrayList;
|
|
33 |
import java.util.Collection;
|
|
34 |
import java.util.List;
|
|
35 |
|
|
36 |
import org.graalvm.compiler.jtt.JTTTest;
|
|
37 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
38 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
|
39 |
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
|
|
40 |
import org.junit.Test;
|
|
41 |
import org.junit.runner.RunWith;
|
|
42 |
import org.junit.runners.Parameterized;
|
|
43 |
|
|
44 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
45 |
|
|
46 |
@RunWith(Parameterized.class)
|
|
47 |
public class IfNodeCanonicalizationsTest extends JTTTest {
|
|
48 |
|
|
49 |
@Override
|
|
50 |
protected InlineInvokePlugin.InlineInfo bytecodeParserShouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
|
|
51 |
if (method.getDeclaringClass().getUnqualifiedName().equals(IfNodeCanonicalizationsTest.class.getSimpleName()) && method.getName().startsWith("compare")) {
|
|
52 |
return InlineInvokePlugin.InlineInfo.createStandardInlineInfo(method);
|
|
53 |
}
|
|
54 |
return super.bytecodeParserShouldInlineInvoke(b, method, args);
|
|
55 |
}
|
|
56 |
|
|
57 |
@Parameter(value = 0) public String testName;
|
|
58 |
@Parameter(value = 1) public int x;
|
|
59 |
@Parameter(value = 2) public int y;
|
|
60 |
|
|
61 |
public static int compare0(int a, int b) {
|
|
62 |
return (a < b) ? 1 : ((a < b) ? 2 : 3);
|
|
63 |
}
|
|
64 |
|
|
65 |
public static int compare1(int a, int b) {
|
|
66 |
return (a < b) ? ((a < b) ? 1 : 2) : 3;
|
|
67 |
}
|
|
68 |
|
|
69 |
public static int compare2(int a, int b) {
|
|
70 |
return (a < b) ? 1 : ((a > b) ? 2 : 3);
|
|
71 |
}
|
|
72 |
|
|
73 |
public static int compare3(int a, int b) {
|
|
74 |
return (a < b) ? ((a > b) ? 1 : 2) : 3;
|
|
75 |
}
|
|
76 |
|
|
77 |
public static int compare4(int a, int b) {
|
|
78 |
return (a < b) ? 1 : ((a <= b) ? 2 : 3);
|
|
79 |
}
|
|
80 |
|
|
81 |
public static int compare5(int a, int b) {
|
|
82 |
return (a < b) ? ((a <= b) ? 1 : 2) : 3;
|
|
83 |
}
|
|
84 |
|
|
85 |
public static int compare6(int a, int b) {
|
|
86 |
return (a < b) ? 1 : ((a >= b) ? 2 : 3);
|
|
87 |
}
|
|
88 |
|
|
89 |
public static int compare7(int a, int b) {
|
|
90 |
return (a < b) ? ((a >= b) ? 1 : 2) : 3;
|
|
91 |
}
|
|
92 |
|
|
93 |
public static int compare8(int a, int b) {
|
|
94 |
return (a < b) ? 1 : ((a == b) ? 2 : 3);
|
|
95 |
}
|
|
96 |
|
|
97 |
public static int compare9(int a, int b) {
|
|
98 |
return (a < b) ? ((a == b) ? 1 : 2) : 3;
|
|
99 |
}
|
|
100 |
|
|
101 |
public static int compare10(int a, int b) {
|
|
102 |
return (a < b) ? 1 : ((a != b) ? 2 : 3);
|
|
103 |
}
|
|
104 |
|
|
105 |
public static int compare11(int a, int b) {
|
|
106 |
return (a < b) ? ((a != b) ? 1 : 2) : 3;
|
|
107 |
}
|
|
108 |
|
|
109 |
public static int compare12(int a, int b) {
|
|
110 |
return (a > b) ? 1 : ((a < b) ? 2 : 3);
|
|
111 |
}
|
|
112 |
|
|
113 |
public static int compare13(int a, int b) {
|
|
114 |
return (a > b) ? ((a < b) ? 1 : 2) : 3;
|
|
115 |
}
|
|
116 |
|
|
117 |
public static int compare14(int a, int b) {
|
|
118 |
return (a > b) ? 1 : ((a > b) ? 2 : 3);
|
|
119 |
}
|
|
120 |
|
|
121 |
public static int compare15(int a, int b) {
|
|
122 |
return (a > b) ? ((a > b) ? 1 : 2) : 3;
|
|
123 |
}
|
|
124 |
|
|
125 |
public static int compare16(int a, int b) {
|
|
126 |
return (a > b) ? 1 : ((a <= b) ? 2 : 3);
|
|
127 |
}
|
|
128 |
|
|
129 |
public static int compare17(int a, int b) {
|
|
130 |
return (a > b) ? ((a <= b) ? 1 : 2) : 3;
|
|
131 |
}
|
|
132 |
|
|
133 |
public static int compare18(int a, int b) {
|
|
134 |
return (a > b) ? 1 : ((a >= b) ? 2 : 3);
|
|
135 |
}
|
|
136 |
|
|
137 |
public static int compare19(int a, int b) {
|
|
138 |
return (a > b) ? ((a >= b) ? 1 : 2) : 3;
|
|
139 |
}
|
|
140 |
|
|
141 |
public static int compare20(int a, int b) {
|
|
142 |
return (a > b) ? 1 : ((a == b) ? 2 : 3);
|
|
143 |
}
|
|
144 |
|
|
145 |
public static int compare21(int a, int b) {
|
|
146 |
return (a > b) ? ((a == b) ? 1 : 2) : 3;
|
|
147 |
}
|
|
148 |
|
|
149 |
public static int compare22(int a, int b) {
|
|
150 |
return (a > b) ? 1 : ((a != b) ? 2 : 3);
|
|
151 |
}
|
|
152 |
|
|
153 |
public static int compare23(int a, int b) {
|
|
154 |
return (a > b) ? ((a != b) ? 1 : 2) : 3;
|
|
155 |
}
|
|
156 |
|
|
157 |
public static int compare24(int a, int b) {
|
|
158 |
return (a <= b) ? 1 : ((a < b) ? 2 : 3);
|
|
159 |
}
|
|
160 |
|
|
161 |
public static int compare25(int a, int b) {
|
|
162 |
return (a <= b) ? ((a < b) ? 1 : 2) : 3;
|
|
163 |
}
|
|
164 |
|
|
165 |
public static int compare26(int a, int b) {
|
|
166 |
return (a <= b) ? 1 : ((a > b) ? 2 : 3);
|
|
167 |
}
|
|
168 |
|
|
169 |
public static int compare27(int a, int b) {
|
|
170 |
return (a <= b) ? ((a > b) ? 1 : 2) : 3;
|
|
171 |
}
|
|
172 |
|
|
173 |
public static int compare28(int a, int b) {
|
|
174 |
return (a <= b) ? 1 : ((a <= b) ? 2 : 3);
|
|
175 |
}
|
|
176 |
|
|
177 |
public static int compare29(int a, int b) {
|
|
178 |
return (a <= b) ? ((a <= b) ? 1 : 2) : 3;
|
|
179 |
}
|
|
180 |
|
|
181 |
public static int compare30(int a, int b) {
|
|
182 |
return (a <= b) ? 1 : ((a >= b) ? 2 : 3);
|
|
183 |
}
|
|
184 |
|
|
185 |
public static int compare31(int a, int b) {
|
|
186 |
return (a <= b) ? ((a >= b) ? 1 : 2) : 3;
|
|
187 |
}
|
|
188 |
|
|
189 |
public static int compare32(int a, int b) {
|
|
190 |
return (a <= b) ? 1 : ((a == b) ? 2 : 3);
|
|
191 |
}
|
|
192 |
|
|
193 |
public static int compare33(int a, int b) {
|
|
194 |
return (a <= b) ? ((a == b) ? 1 : 2) : 3;
|
|
195 |
}
|
|
196 |
|
|
197 |
public static int compare34(int a, int b) {
|
|
198 |
return (a <= b) ? 1 : ((a != b) ? 2 : 3);
|
|
199 |
}
|
|
200 |
|
|
201 |
public static int compare35(int a, int b) {
|
|
202 |
return (a <= b) ? ((a != b) ? 1 : 2) : 3;
|
|
203 |
}
|
|
204 |
|
|
205 |
public static int compare36(int a, int b) {
|
|
206 |
return (a >= b) ? 1 : ((a < b) ? 2 : 3);
|
|
207 |
}
|
|
208 |
|
|
209 |
public static int compare37(int a, int b) {
|
|
210 |
return (a >= b) ? ((a < b) ? 1 : 2) : 3;
|
|
211 |
}
|
|
212 |
|
|
213 |
public static int compare38(int a, int b) {
|
|
214 |
return (a >= b) ? 1 : ((a > b) ? 2 : 3);
|
|
215 |
}
|
|
216 |
|
|
217 |
public static int compare39(int a, int b) {
|
|
218 |
return (a >= b) ? ((a > b) ? 1 : 2) : 3;
|
|
219 |
}
|
|
220 |
|
|
221 |
public static int compare40(int a, int b) {
|
|
222 |
return (a >= b) ? 1 : ((a <= b) ? 2 : 3);
|
|
223 |
}
|
|
224 |
|
|
225 |
public static int compare41(int a, int b) {
|
|
226 |
return (a >= b) ? ((a <= b) ? 1 : 2) : 3;
|
|
227 |
}
|
|
228 |
|
|
229 |
public static int compare42(int a, int b) {
|
|
230 |
return (a >= b) ? 1 : ((a >= b) ? 2 : 3);
|
|
231 |
}
|
|
232 |
|
|
233 |
public static int compare43(int a, int b) {
|
|
234 |
return (a >= b) ? ((a >= b) ? 1 : 2) : 3;
|
|
235 |
}
|
|
236 |
|
|
237 |
public static int compare44(int a, int b) {
|
|
238 |
return (a >= b) ? 1 : ((a == b) ? 2 : 3);
|
|
239 |
}
|
|
240 |
|
|
241 |
public static int compare45(int a, int b) {
|
|
242 |
return (a >= b) ? ((a == b) ? 1 : 2) : 3;
|
|
243 |
}
|
|
244 |
|
|
245 |
public static int compare46(int a, int b) {
|
|
246 |
return (a >= b) ? 1 : ((a != b) ? 2 : 3);
|
|
247 |
}
|
|
248 |
|
|
249 |
public static int compare47(int a, int b) {
|
|
250 |
return (a >= b) ? ((a != b) ? 1 : 2) : 3;
|
|
251 |
}
|
|
252 |
|
|
253 |
public static int compare48(int a, int b) {
|
|
254 |
return (a == b) ? 1 : ((a < b) ? 2 : 3);
|
|
255 |
}
|
|
256 |
|
|
257 |
public static int compare49(int a, int b) {
|
|
258 |
return (a == b) ? ((a < b) ? 1 : 2) : 3;
|
|
259 |
}
|
|
260 |
|
|
261 |
public static int compare50(int a, int b) {
|
|
262 |
return (a == b) ? 1 : ((a > b) ? 2 : 3);
|
|
263 |
}
|
|
264 |
|
|
265 |
public static int compare51(int a, int b) {
|
|
266 |
return (a == b) ? ((a > b) ? 1 : 2) : 3;
|
|
267 |
}
|
|
268 |
|
|
269 |
public static int compare52(int a, int b) {
|
|
270 |
return (a == b) ? 1 : ((a <= b) ? 2 : 3);
|
|
271 |
}
|
|
272 |
|
|
273 |
public static int compare53(int a, int b) {
|
|
274 |
return (a == b) ? ((a <= b) ? 1 : 2) : 3;
|
|
275 |
}
|
|
276 |
|
|
277 |
public static int compare54(int a, int b) {
|
|
278 |
return (a == b) ? 1 : ((a >= b) ? 2 : 3);
|
|
279 |
}
|
|
280 |
|
|
281 |
public static int compare55(int a, int b) {
|
|
282 |
return (a == b) ? ((a >= b) ? 1 : 2) : 3;
|
|
283 |
}
|
|
284 |
|
|
285 |
public static int compare56(int a, int b) {
|
|
286 |
return (a == b) ? 1 : ((a == b) ? 2 : 3);
|
|
287 |
}
|
|
288 |
|
|
289 |
public static int compare57(int a, int b) {
|
|
290 |
return (a == b) ? ((a == b) ? 1 : 2) : 3;
|
|
291 |
}
|
|
292 |
|
|
293 |
public static int compare58(int a, int b) {
|
|
294 |
return (a == b) ? 1 : ((a != b) ? 2 : 3);
|
|
295 |
}
|
|
296 |
|
|
297 |
public static int compare59(int a, int b) {
|
|
298 |
return (a == b) ? ((a != b) ? 1 : 2) : 3;
|
|
299 |
}
|
|
300 |
|
|
301 |
public static int compare60(int a, int b) {
|
|
302 |
return (a != b) ? 1 : ((a < b) ? 2 : 3);
|
|
303 |
}
|
|
304 |
|
|
305 |
public static int compare61(int a, int b) {
|
|
306 |
return (a != b) ? ((a < b) ? 1 : 2) : 3;
|
|
307 |
}
|
|
308 |
|
|
309 |
public static int compare62(int a, int b) {
|
|
310 |
return (a != b) ? 1 : ((a > b) ? 2 : 3);
|
|
311 |
}
|
|
312 |
|
|
313 |
public static int compare63(int a, int b) {
|
|
314 |
return (a != b) ? ((a > b) ? 1 : 2) : 3;
|
|
315 |
}
|
|
316 |
|
|
317 |
public static int compare64(int a, int b) {
|
|
318 |
return (a != b) ? 1 : ((a <= b) ? 2 : 3);
|
|
319 |
}
|
|
320 |
|
|
321 |
public static int compare65(int a, int b) {
|
|
322 |
return (a != b) ? ((a <= b) ? 1 : 2) : 3;
|
|
323 |
}
|
|
324 |
|
|
325 |
public static int compare66(int a, int b) {
|
|
326 |
return (a != b) ? 1 : ((a >= b) ? 2 : 3);
|
|
327 |
}
|
|
328 |
|
|
329 |
public static int compare67(int a, int b) {
|
|
330 |
return (a != b) ? ((a >= b) ? 1 : 2) : 3;
|
|
331 |
}
|
|
332 |
|
|
333 |
public static int compare68(int a, int b) {
|
|
334 |
return (a != b) ? 1 : ((a == b) ? 2 : 3);
|
|
335 |
}
|
|
336 |
|
|
337 |
public static int compare69(int a, int b) {
|
|
338 |
return (a != b) ? ((a == b) ? 1 : 2) : 3;
|
|
339 |
}
|
|
340 |
|
|
341 |
public static int compare70(int a, int b) {
|
|
342 |
return (a != b) ? 1 : ((a != b) ? 2 : 3);
|
|
343 |
}
|
|
344 |
|
|
345 |
public static int compare71(int a, int b) {
|
|
346 |
return (a != b) ? ((a != b) ? 1 : 2) : 3;
|
|
347 |
}
|
|
348 |
|
|
349 |
@Test
|
|
350 |
public void runNamedTest() {
|
|
351 |
runTest(testName, x, y);
|
|
352 |
}
|
|
353 |
|
|
354 |
@Parameters(name = "{0}(a = {1}, b = {2})")
|
|
355 |
public static Collection<Object[]> data() {
|
|
356 |
List<Object[]> tests = new ArrayList<>();
|
|
357 |
for (Method m : IfNodeCanonicalizationsTest.class.getDeclaredMethods()) {
|
|
358 |
if (m.getName().startsWith("compare") && Modifier.isStatic(m.getModifiers())) {
|
|
359 |
tests.add(new Object[]{m.getName(), 0, 0});
|
|
360 |
tests.add(new Object[]{m.getName(), 0, 1});
|
|
361 |
tests.add(new Object[]{m.getName(), 1, 0});
|
|
362 |
}
|
|
363 |
}
|
|
364 |
return tests;
|
|
365 |
}
|
|
366 |
}
|