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.debug.Debug;
28 import org.graalvm.compiler.nodes.StructuredGraph;
29 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
30 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
31 import org.graalvm.compiler.phases.tiers.PhaseContext;
32
33 /**
34 * In the following tests, the scalar type system of the compiler should be complete enough to see
35 * the relation between the different conditions.
36 */
37 public class ScalarTypeSystemTest extends GraalCompilerTest {
38
39 public static int referenceSnippet1(int a) {
40 if (a > 0) {
41 return 1;
42 } else {
43 return 2;
44 }
45 }
46
47 @Test(expected = AssertionError.class)
48 public void test1() {
49 test("test1Snippet", "referenceSnippet1");
50 }
51
114 @Test(expected = AssertionError.class)
115 public void test6() {
116 test("test6Snippet", "referenceSnippet3");
117 }
118
119 public static int test6Snippet(int a, int b) {
120 if (a == b) {
121 if (a == b + 1) {
122 return 3;
123 } else {
124 return 1;
125 }
126 } else {
127 return 2;
128 }
129 }
130
131 private void test(final String snippet, final String referenceSnippet) {
132 // No debug scope to reduce console noise for @Test(expected = ...) tests
133 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
134 Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
135 PhaseContext context = new PhaseContext(getProviders());
136 new CanonicalizerPhase().apply(graph, context);
137 StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
138 assertEquals(referenceGraph, graph);
139 }
140 }
|
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.debug.DebugContext;
26 import org.graalvm.compiler.nodes.StructuredGraph;
27 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
28 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
29 import org.graalvm.compiler.phases.tiers.PhaseContext;
30 import org.junit.Test;
31
32 /**
33 * In the following tests, the scalar type system of the compiler should be complete enough to see
34 * the relation between the different conditions.
35 */
36 public class ScalarTypeSystemTest extends GraalCompilerTest {
37
38 public static int referenceSnippet1(int a) {
39 if (a > 0) {
40 return 1;
41 } else {
42 return 2;
43 }
44 }
45
46 @Test(expected = AssertionError.class)
47 public void test1() {
48 test("test1Snippet", "referenceSnippet1");
49 }
50
113 @Test(expected = AssertionError.class)
114 public void test6() {
115 test("test6Snippet", "referenceSnippet3");
116 }
117
118 public static int test6Snippet(int a, int b) {
119 if (a == b) {
120 if (a == b + 1) {
121 return 3;
122 } else {
123 return 1;
124 }
125 } else {
126 return 2;
127 }
128 }
129
130 private void test(final String snippet, final String referenceSnippet) {
131 // No debug scope to reduce console noise for @Test(expected = ...) tests
132 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
133 graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Graph");
134 PhaseContext context = new PhaseContext(getProviders());
135 new CanonicalizerPhase().apply(graph, context);
136 StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
137 assertEquals(referenceGraph, graph);
138 }
139 }
|