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 package org.graalvm.compiler.core.test;
24
25 import org.junit.Test;
26
27 import org.graalvm.compiler.nodes.StructuredGraph;
28 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
29 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
30 import org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase;
31 import org.graalvm.compiler.phases.tiers.HighTierContext;
32
33 public class ConditionalEliminationMulTest extends GraalCompilerTest {
34
35 public static void snippet01(int a) {
36 if (a == 2) {
37 if (a * 3 != 6) {
38 shouldBeOptimizedAway();
39 }
40 }
41 }
42
43 public static void snippet02(int a) {
44 if (a == 0) {
45 if (a * 3 != 0) {
46 shouldBeOptimizedAway();
47 }
48 }
49 }
50
51 public static void snippet03(int a) {
59 assertOptimized("snippet01");
60 }
61
62 @Test
63 public void testConditionalEliminated02() {
64 assertOptimized("snippet02");
65 }
66
67 @Test
68 public void testConditionalEliminated03() {
69 assertOptimized("snippet03");
70 }
71
72 private void assertOptimized(String snippet) {
73 assertOptimizedAway(prepareGraph(snippet));
74 }
75
76 private StructuredGraph prepareGraph(String snippet) {
77 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
78 HighTierContext context = getDefaultHighTierContext();
79 CanonicalizerPhase c = new CanonicalizerPhase();
80 c.apply(graph, context);
81 new DominatorConditionalEliminationPhase(false).apply(graph, context);
82 c.apply(graph, context);
83 return graph;
84 }
85
86 }
|
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 package org.graalvm.compiler.core.test;
24
25 import org.graalvm.compiler.nodes.StructuredGraph;
26 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
27 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
28 import org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase;
29 import org.graalvm.compiler.phases.tiers.HighTierContext;
30 import org.junit.Test;
31
32 public class ConditionalEliminationMulTest extends GraalCompilerTest {
33
34 public static void snippet01(int a) {
35 if (a == 2) {
36 if (a * 3 != 6) {
37 shouldBeOptimizedAway();
38 }
39 }
40 }
41
42 public static void snippet02(int a) {
43 if (a == 0) {
44 if (a * 3 != 0) {
45 shouldBeOptimizedAway();
46 }
47 }
48 }
49
50 public static void snippet03(int a) {
58 assertOptimized("snippet01");
59 }
60
61 @Test
62 public void testConditionalEliminated02() {
63 assertOptimized("snippet02");
64 }
65
66 @Test
67 public void testConditionalEliminated03() {
68 assertOptimized("snippet03");
69 }
70
71 private void assertOptimized(String snippet) {
72 assertOptimizedAway(prepareGraph(snippet));
73 }
74
75 private StructuredGraph prepareGraph(String snippet) {
76 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
77 HighTierContext context = getDefaultHighTierContext();
78 DominatorConditionalEliminationPhase.create(false).apply(graph, context);
79 CanonicalizerPhase c = new CanonicalizerPhase();
80 c.apply(graph, context);
81 return graph;
82 }
83 }
|