# HG changeset patch # User Thomas Wuerthinger # Date 1433627559 -7200 # Node ID cb6d65bcc8cba983bd87d3ee6a7baa4ef825d866 # Parent 1ab2c7bb6f0f5ee3967252de6f9aa9d215066e30 Fix the guard anchors in the lowering phase and add a simple test case to prevent future regressions. diff -r 1ab2c7bb6f0f -r cb6d65bcc8cb graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest10.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest10.java Sat Jun 06 23:52:39 2015 +0200 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.test; + +import org.junit.*; + +import com.oracle.graal.api.directives.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.StructuredGraph.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; + +/** + * This test checks the combined action of + * {@link com.oracle.graal.phases.common.DominatorConditionalEliminationPhase} and + * {@link com.oracle.graal.phases.common.LoweringPhase}. The lowering phase needs to introduce the + * null checks at the correct places for the dominator conditional elimination phase to pick them + * up. + */ +public class ConditionalEliminationTest10 extends ConditionalEliminationTestBase { + + private static class TestClass { + int x; + } + + @SuppressWarnings("all") + public static int testSnippet(int a, TestClass t) { + int result = 0; + if (a == 0) { + GraalDirectives.controlFlowAnchor(); + result = t.x; + } + GraalDirectives.controlFlowAnchor(); + return result + t.x; + } + + @Test + public void test1() { + StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES); + PhaseContext context = new PhaseContext(getProviders()); + new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); + Assert.assertEquals(2, graph.getNodes().filter(GuardNode.class).count()); + new DominatorConditionalEliminationPhase(true).apply(graph, context); + Assert.assertEquals(1, graph.getNodes().filter(GuardNode.class).count()); + } +} diff -r 1ab2c7bb6f0f -r cb6d65bcc8cb graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Sat Jun 06 22:19:26 2015 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Sat Jun 06 23:52:39 2015 +0200 @@ -256,6 +256,7 @@ @Override public void run(StructuredGraph graph) { schedule.apply(graph, false); + schedule.getCFG().computePostdominators(); Block startBlock = schedule.getCFG().getStartBlock(); ProcessFrame rootFrame = new ProcessFrame(startBlock, graph.createNodeBitMap(), startBlock.getBeginNode(), null); LoweringPhase.processBlock(rootFrame); @@ -400,7 +401,7 @@ * if (alwaysReachedBlock != null && alwaysReachedBlock.getDominator() == block) { * processBlock(alwaysReachedBlock); * } - * + * * // Now go for the other dominators. * for (Block dominated : block.getDominated()) { * if (dominated != alwaysReachedBlock) {