changeset 21764:cb6d65bcc8cb

Fix the guard anchors in the lowering phase and add a simple test case to prevent future regressions.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 06 Jun 2015 23:52:39 +0200
parents 1ab2c7bb6f0f
children a7a1b9b65bce
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest10.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java
diffstat 2 files changed, 69 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /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());
+    }
+}
--- 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 &amp;&amp; alwaysReachedBlock.getDominator() == block) {
      *         processBlock(alwaysReachedBlock);
      *     }
-     *
+     * 
      *     // Now go for the other dominators.
      *     for (Block dominated : block.getDominated()) {
      *         if (dominated != alwaysReachedBlock) {