1 /* |
1 /* |
2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
31 import org.graalvm.compiler.nodes.ReturnNode; |
31 import org.graalvm.compiler.nodes.ReturnNode; |
32 import org.graalvm.compiler.nodes.StructuredGraph; |
32 import org.graalvm.compiler.nodes.StructuredGraph; |
33 import org.graalvm.compiler.phases.OptimisticOptimizations; |
33 import org.graalvm.compiler.phases.OptimisticOptimizations; |
34 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
34 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
35 import org.graalvm.compiler.phases.tiers.HighTierContext; |
35 import org.graalvm.compiler.phases.tiers.HighTierContext; |
36 import org.graalvm.compiler.phases.tiers.PhaseContext; |
|
37 import org.graalvm.compiler.replacements.nodes.ArrayEqualsNode; |
36 import org.graalvm.compiler.replacements.nodes.ArrayEqualsNode; |
38 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase; |
37 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase; |
39 import org.junit.Assert; |
38 import org.junit.Assert; |
40 import org.junit.Test; |
39 import org.junit.Test; |
41 |
40 |
131 @Test |
130 @Test |
132 public void testCanonicalLength() { |
131 public void testCanonicalLength() { |
133 StructuredGraph graph = parseEager("testCanonicalLengthSnippet", AllowAssumptions.NO); |
132 StructuredGraph graph = parseEager("testCanonicalLengthSnippet", AllowAssumptions.NO); |
134 HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); |
133 HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); |
135 createInliningPhase().apply(graph, context); |
134 createInliningPhase().apply(graph, context); |
136 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders())); |
135 new CanonicalizerPhase().apply(graph, getProviders()); |
137 |
136 |
138 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 0); |
137 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 0); |
139 } |
138 } |
140 |
139 |
141 public static final int[] constantArray3 = new int[]{1, 2, 3}; |
140 public static final int[] constantArray3 = new int[]{1, 2, 3}; |
147 @Test |
146 @Test |
148 public void testCanonicalEqual() { |
147 public void testCanonicalEqual() { |
149 StructuredGraph graph = parseEager("testCanonicalEqualSnippet", AllowAssumptions.NO); |
148 StructuredGraph graph = parseEager("testCanonicalEqualSnippet", AllowAssumptions.NO); |
150 HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); |
149 HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); |
151 createInliningPhase().apply(graph, context); |
150 createInliningPhase().apply(graph, context); |
152 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders())); |
151 new CanonicalizerPhase().apply(graph, getProviders()); |
153 |
152 |
154 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 1); |
153 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 1); |
155 } |
154 } |
156 |
155 |
157 public static boolean testCanonicalEqualSnippet() { |
156 public static boolean testCanonicalEqualSnippet() { |
161 @Test |
160 @Test |
162 public void testVirtualEqual() { |
161 public void testVirtualEqual() { |
163 StructuredGraph graph = parseEager("testVirtualEqualSnippet", AllowAssumptions.NO); |
162 StructuredGraph graph = parseEager("testVirtualEqualSnippet", AllowAssumptions.NO); |
164 HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); |
163 HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); |
165 createInliningPhase().apply(graph, context); |
164 createInliningPhase().apply(graph, context); |
166 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders())); |
165 new CanonicalizerPhase().apply(graph, getProviders()); |
167 new PartialEscapePhase(false, new CanonicalizerPhase(), graph.getOptions()).apply(graph, context); |
166 new PartialEscapePhase(false, new CanonicalizerPhase(), graph.getOptions()).apply(graph, context); |
168 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders())); |
167 new CanonicalizerPhase().apply(graph, getProviders()); |
169 |
168 |
170 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 1); |
169 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 1); |
171 } |
170 } |
172 |
171 |
173 public static boolean testVirtualEqualSnippet() { |
172 public static boolean testVirtualEqualSnippet() { |
179 @Test |
178 @Test |
180 public void testVirtualNotEqual() { |
179 public void testVirtualNotEqual() { |
181 StructuredGraph graph = parseEager("testVirtualNotEqualSnippet", AllowAssumptions.NO); |
180 StructuredGraph graph = parseEager("testVirtualNotEqualSnippet", AllowAssumptions.NO); |
182 HighTierContext context = getDefaultHighTierContext(); |
181 HighTierContext context = getDefaultHighTierContext(); |
183 createInliningPhase().apply(graph, context); |
182 createInliningPhase().apply(graph, context); |
184 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders())); |
183 new CanonicalizerPhase().apply(graph, getProviders()); |
185 new PartialEscapePhase(false, new CanonicalizerPhase(), graph.getOptions()).apply(graph, context); |
184 new PartialEscapePhase(false, new CanonicalizerPhase(), graph.getOptions()).apply(graph, context); |
186 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders())); |
185 new CanonicalizerPhase().apply(graph, getProviders()); |
187 |
186 |
188 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 0); |
187 Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 0); |
189 } |
188 } |
190 |
189 |
191 public static boolean testVirtualNotEqualSnippet(int x) { |
190 public static boolean testVirtualNotEqualSnippet(int x) { |