1 /* 2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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.Assert; 26 import org.junit.Test; 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 }