27 28 import org.graalvm.compiler.api.directives.GraalDirectives; 29 import org.graalvm.compiler.nodes.GuardNode; 30 import org.graalvm.compiler.nodes.StructuredGraph; 31 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 32 import org.graalvm.compiler.nodes.spi.LoweringTool; 33 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 34 import org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase; 35 import org.graalvm.compiler.phases.common.LoweringPhase; 36 import org.graalvm.compiler.phases.tiers.PhaseContext; 37 38 /** 39 * This test checks the combined action of 40 * {@link org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase} and 41 * {@link org.graalvm.compiler.phases.common.LoweringPhase}. The lowering phase needs to introduce 42 * the null checks at the correct places for the dominator conditional elimination phase to pick 43 * them up. 44 */ 45 public class ConditionalEliminationTest10 extends ConditionalEliminationTestBase { 46 47 private static class TestClass { 48 int x; 49 } 50 51 @SuppressWarnings("all") 52 public static int testSnippet(int a, TestClass t) { 53 int result = 0; 54 if (a == 0) { 55 GraalDirectives.controlFlowAnchor(); 56 result = t.x; 57 } 58 GraalDirectives.controlFlowAnchor(); 59 return result + t.x; 60 } 61 62 @Test 63 public void test1() { 64 StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES); 65 PhaseContext context = new PhaseContext(getProviders()); 66 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); 67 Assert.assertEquals(2, graph.getNodes().filter(GuardNode.class).count()); 68 new DominatorConditionalEliminationPhase(true).apply(graph, context); 69 Assert.assertEquals(1, graph.getNodes().filter(GuardNode.class).count()); 70 } 71 } | 27 28 import org.graalvm.compiler.api.directives.GraalDirectives; 29 import org.graalvm.compiler.nodes.GuardNode; 30 import org.graalvm.compiler.nodes.StructuredGraph; 31 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 32 import org.graalvm.compiler.nodes.spi.LoweringTool; 33 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 34 import org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase; 35 import org.graalvm.compiler.phases.common.LoweringPhase; 36 import org.graalvm.compiler.phases.tiers.PhaseContext; 37 38 /** 39 * This test checks the combined action of 40 * {@link org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase} and 41 * {@link org.graalvm.compiler.phases.common.LoweringPhase}. The lowering phase needs to introduce 42 * the null checks at the correct places for the dominator conditional elimination phase to pick 43 * them up. 44 */ 45 public class ConditionalEliminationTest10 extends ConditionalEliminationTestBase { 46 47 private static boolean condition1; 48 private static boolean condition2; 49 50 private static class TestClass { 51 int x; 52 } 53 54 @SuppressWarnings("all") 55 public static int testSnippet1(TestClass t) { 56 int result = 0; 57 if (condition1) { 58 GraalDirectives.controlFlowAnchor(); 59 result = t.x; 60 } 61 GraalDirectives.controlFlowAnchor(); 62 return result + t.x; 63 } 64 65 @Test 66 public void test1() { 67 test("testSnippet1", 1); 68 } 69 70 @SuppressWarnings("all") 71 public static int testSnippet2(TestClass t) { 72 int result = 0; 73 if (condition1) { 74 GraalDirectives.controlFlowAnchor(); 75 result = t.x; 76 } else { 77 GraalDirectives.controlFlowAnchor(); 78 result = t.x; 79 } 80 81 if (condition2) { 82 result = t.x; 83 GraalDirectives.controlFlowAnchor(); 84 } 85 86 return result; 87 } 88 89 @Test 90 public void test2() { 91 test("testSnippet2", 1); 92 } 93 94 private void test(String snippet, int guardCount) { 95 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); 96 PhaseContext context = new PhaseContext(getProviders()); 97 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); 98 DominatorConditionalEliminationPhase.create(true).apply(graph, context); 99 Assert.assertEquals(guardCount, graph.getNodes().filter(GuardNode.class).count()); 100 } 101 } |