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 public class StraighteningTest extends GraalCompilerTest {
34
35 private static final String REFERENCE_SNIPPET = "ref";
36
37 public static boolean ref(int a, int b) {
38 return a == b;
39 }
40
41 public static boolean test1Snippet(int a, int b) {
42 int c = a;
43 if (c == b) {
44 c = 0x55;
45 }
46 if (c != 0x55) {
47 return false;
48 }
49 return true;
50 }
51
71 return c == 1;
72 }
73
74 @Test(expected = AssertionError.class)
75 public void test1() {
76 test("test1Snippet");
77 }
78
79 public void test2() {
80 test("test2Snippet");
81 }
82
83 @Test(expected = AssertionError.class)
84 public void test3() {
85 test("test3Snippet");
86 }
87
88 private void test(final String snippet) {
89 // No debug scope to reduce console noise for @Test(expected = ...) tests
90 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
91 Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
92 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
93 StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
94 assertEquals(referenceGraph, graph);
95 }
96 }
|
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 public class StraighteningTest extends GraalCompilerTest {
33
34 private static final String REFERENCE_SNIPPET = "ref";
35
36 public static boolean ref(int a, int b) {
37 return a == b;
38 }
39
40 public static boolean test1Snippet(int a, int b) {
41 int c = a;
42 if (c == b) {
43 c = 0x55;
44 }
45 if (c != 0x55) {
46 return false;
47 }
48 return true;
49 }
50
70 return c == 1;
71 }
72
73 @Test(expected = AssertionError.class)
74 public void test1() {
75 test("test1Snippet");
76 }
77
78 public void test2() {
79 test("test2Snippet");
80 }
81
82 @Test(expected = AssertionError.class)
83 public void test3() {
84 test("test3Snippet");
85 }
86
87 private void test(final String snippet) {
88 // No debug scope to reduce console noise for @Test(expected = ...) tests
89 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
90 DebugContext debug = graph.getDebug();
91 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
92 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
93 StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
94 assertEquals(referenceGraph, graph);
95 }
96 }
|