ConditionalEliminationTest11.java revision 12651:6ef01bd40ce2
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 */
23package org.graalvm.compiler.core.test;
24
25import org.junit.Ignore;
26import org.junit.Test;
27
28import org.graalvm.compiler.api.directives.GraalDirectives;
29
30/**
31 * Collection of tests for
32 * {@link org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase} including those
33 * that triggered bugs in this phase.
34 */
35public class ConditionalEliminationTest11 extends ConditionalEliminationTestBase {
36    public ConditionalEliminationTest11() {
37        // Don't disable simplification
38        super(false);
39    }
40
41    @SuppressWarnings("all")
42    public static int referenceSnippet(int a) {
43        if ((a & 15) != 15) {
44            GraalDirectives.deoptimize();
45        }
46        return 0;
47    }
48
49    @Test
50    public void test1() {
51        testConditionalElimination("test1Snippet", "referenceSnippet");
52    }
53
54    @SuppressWarnings("all")
55    public static int test1Snippet(int a) {
56        if ((a & 8) != 8) {
57            GraalDirectives.deoptimize();
58        }
59        if ((a & 15) != 15) {
60            GraalDirectives.deoptimize();
61        }
62        return 0;
63    }
64
65    @SuppressWarnings("all")
66    public static int test2Snippet(int a) {
67        if ((a & 8) == 0) {
68            GraalDirectives.deoptimize();
69        }
70        if ((a & 15) != 15) {
71            GraalDirectives.deoptimize();
72        }
73        return 0;
74    }
75
76    @Test
77    public void test2() {
78        testConditionalElimination("test2Snippet", "referenceSnippet");
79    }
80
81    @SuppressWarnings("all")
82    public static int test3Snippet(int a) {
83        if ((a & 15) != 15) {
84            GraalDirectives.deoptimize();
85        }
86        if ((a & 8) != 8) {
87            GraalDirectives.deoptimize();
88        }
89        return 0;
90    }
91
92    @Test
93    public void test3() {
94        // Test forward elimination of bitwise tests
95        testConditionalElimination("test3Snippet", "referenceSnippet");
96    }
97
98    @SuppressWarnings("all")
99    public static int test4Snippet(int a) {
100        if ((a & 15) != 15) {
101            GraalDirectives.deoptimize();
102        }
103        if ((a & 8) == 0) {
104            GraalDirectives.deoptimize();
105        }
106        return 0;
107    }
108
109    @Test
110    public void test4() {
111        // Test forward elimination of bitwise tests
112        testConditionalElimination("test4Snippet", "referenceSnippet");
113    }
114
115    public static int test5Snippet(int a) {
116        if ((a & 5) == 5) {
117            GraalDirectives.deoptimize();
118        }
119        if ((a & 7) != 0) {
120            return 0;
121        }
122        return 1;
123    }
124
125    @Test
126    public void test5() {
127        // Shouldn't be possible to optimize this
128        testConditionalElimination("test5Snippet", "test5Snippet");
129    }
130
131    public static int test6Snippet(int a) {
132        if ((a & 8) != 0) {
133            GraalDirectives.deoptimize();
134        }
135        if ((a & 15) != 15) {
136            GraalDirectives.deoptimize();
137        }
138        return 0;
139    }
140
141    public static int reference6Snippet(int a) {
142        if ((a & 8) != 0) {
143            GraalDirectives.deoptimize();
144        }
145        GraalDirectives.deoptimize();
146        return 0;
147    }
148
149    @Test
150    public void test6() {
151        testConditionalElimination("test6Snippet", "reference6Snippet");
152    }
153
154    public static int test7Snippet(int a) {
155        if ((a & 15) == 15) {
156            GraalDirectives.deoptimize();
157        }
158        if ((a & 8) == 8) {
159            GraalDirectives.deoptimize();
160        }
161        return a;
162    }
163
164    public static int reference7Snippet(int a) {
165        if ((a & 8) == 8) {
166            GraalDirectives.deoptimize();
167        }
168        return a;
169    }
170
171    @Test
172    public void test7() {
173        testConditionalElimination("test7Snippet", "reference7Snippet");
174    }
175
176    public static int test8Snippet(int a) {
177        if ((a & 16) == 16) {
178            GraalDirectives.deoptimize();
179        }
180        if ((a & 8) != 8) {
181            GraalDirectives.deoptimize();
182        }
183        if ((a & 44) != 44) {
184            GraalDirectives.deoptimize();
185        }
186        return a;
187    }
188
189    public static int reference8Snippet(int a) {
190        if ((a & 60) != 44) {
191            GraalDirectives.deoptimize();
192        }
193        return a;
194    }
195
196    @Ignore("requires merging of bit tests")
197    @Test
198    public void test8() {
199        testConditionalElimination("test8Snippet", "reference8Snippet");
200    }
201
202    public static int test9Snippet(int a) {
203        if ((a & 16) == 16) {
204            GraalDirectives.deoptimize();
205        }
206        if ((a & 8) != 8) {
207            GraalDirectives.deoptimize();
208        }
209        if ((a & 44) != 44) {
210            GraalDirectives.deoptimize();
211        }
212        if (a != 44) {
213            GraalDirectives.deoptimize();
214        }
215        return a;
216    }
217
218    public static int reference9Snippet(int a) {
219        if (a != 44) {
220            GraalDirectives.deoptimize();
221        }
222        return a;
223    }
224
225    @Test
226    public void test9() {
227        testConditionalElimination("test9Snippet", "reference9Snippet");
228    }
229
230    static class ByteHolder {
231        public byte b;
232
233        byte byteValue() {
234            return b;
235        }
236    }
237
238    public static int test10Snippet(ByteHolder b) {
239        int v = b.byteValue();
240        long a = v & 0xffffffff;
241        if (v != 44) {
242            GraalDirectives.deoptimize();
243        }
244        if ((a & 16) == 16) {
245            GraalDirectives.deoptimize();
246        }
247        if ((a & 8) != 8) {
248            GraalDirectives.deoptimize();
249        }
250        if ((a & 44) != 44) {
251            GraalDirectives.deoptimize();
252        }
253
254        return v;
255    }
256
257    public static int reference10Snippet(ByteHolder b) {
258        byte v = b.byteValue();
259        if (v != 44) {
260            GraalDirectives.deoptimize();
261        }
262        return v;
263    }
264
265    @Test
266    public void test10() {
267        testConditionalElimination("test10Snippet", "reference10Snippet");
268    }
269
270    public static int test11Snippet(ByteHolder b) {
271        int v = b.byteValue();
272        long a = v & 0xffffffff;
273
274        if ((a & 16) == 16) {
275            GraalDirectives.deoptimize();
276        }
277        if ((a & 8) != 8) {
278            GraalDirectives.deoptimize();
279        }
280        if ((a & 44) != 44) {
281            GraalDirectives.deoptimize();
282        }
283        if (v != 44) {
284            GraalDirectives.deoptimize();
285        }
286        return v;
287    }
288
289    public static int reference11Snippet(ByteHolder b) {
290        byte v = b.byteValue();
291        if (v != 44) {
292            GraalDirectives.deoptimize();
293        }
294        return v;
295    }
296
297    @Test
298    public void test11() {
299        testConditionalElimination("test11Snippet", "reference11Snippet");
300    }
301
302}
303