changeset 22935:29114298229f

SPARC-specific canonicalization of sub-int compare
author Stefan Anzinger <stefan.anzinger@oracle.com>
date Tue, 03 Nov 2015 18:14:26 +0100
parents 0fbd1d1b9bcd
children 8e5c7be6d1fb
files graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeMatchRules.java graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCSubIntCompareCanonicalizationPhase.java graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCSuitesProvider.java graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java mx.graal/suite.py
diffstat 7 files changed, 141 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Tue Nov 03 13:30:53 2015 +0100
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Tue Nov 03 18:14:26 2015 +0100
@@ -33,6 +33,7 @@
 import static com.oracle.graal.lir.LIRValueUtil.asJavaConstant;
 import static com.oracle.graal.lir.LIRValueUtil.isJavaConstant;
 import static jdk.vm.ci.sparc.SPARCKind.SINGLE;
+import static jdk.vm.ci.sparc.SPARCKind.WORD;
 import static jdk.vm.ci.sparc.SPARCKind.XWORD;
 import jdk.vm.ci.code.CallingConvention;
 import jdk.vm.ci.common.JVMCIError;
@@ -55,7 +56,6 @@
 import com.oracle.graal.compiler.common.calc.Condition;
 import com.oracle.graal.compiler.common.spi.ForeignCallLinkage;
 import com.oracle.graal.compiler.common.spi.LIRKindTool;
-import com.oracle.graal.lir.ConstantValue;
 import com.oracle.graal.lir.LIR;
 import com.oracle.graal.lir.LIRFrameState;
 import com.oracle.graal.lir.LIRValueUtil;
@@ -212,9 +212,8 @@
         }
         SPARCKind actualCmpKind = (SPARCKind) cmpKind;
         if (actualCmpKind.isInteger()) {
-            actualCmpKind = toSPARCCmpKind(actualCmpKind);
-            append(new SPARCControlFlow.CompareBranchOp(canonicalizeForCompare(left, cmpKind, actualCmpKind), canonicalizeForCompare(right, cmpKind, actualCmpKind), actualCondition, trueDestination,
-                            falseDestination, actualCmpKind, unorderedIsTrue, trueDestinationProbability));
+            assert actualCmpKind.equals(XWORD) || actualCmpKind.equals(WORD) : "SPARC does not support compare of: " + actualCmpKind;
+            append(new SPARCControlFlow.CompareBranchOp(left, right, actualCondition, trueDestination, falseDestination, actualCmpKind, unorderedIsTrue, trueDestinationProbability));
         } else if (actualCmpKind.isFloat()) {
             emitFloatCompare(actualCmpKind, x, y, Fcc0);
             ConditionFlag cf = SPARCControlFlow.fromCondition(false, cond, unorderedIsTrue);
@@ -224,30 +223,6 @@
         }
     }
 
-    private static SPARCKind toSPARCCmpKind(SPARCKind actualCmpKind) {
-        if (actualCmpKind.isInteger() && actualCmpKind.getSizeInBytes() <= 4) {
-            return SPARCKind.WORD;
-        } else {
-            return actualCmpKind;
-        }
-    }
-
-    private Value canonicalizeForCompare(Value v, PlatformKind from, PlatformKind to) {
-        if (LIRValueUtil.isJavaConstant(v)) {
-            JavaConstant c = asJavaConstant(v);
-            return new ConstantValue(v.getLIRKind().changeType(to), c);
-        } else {
-            int fromBytes = from.getSizeInBytes() * 8;
-            int toBytes = to.getSizeInBytes() * 8;
-            assert from.getSizeInBytes() <= v.getPlatformKind().getSizeInBytes();
-            if (from == to) {
-                return v;
-            } else {
-                return arithmeticLIRGen.emitSignExtend(v, fromBytes, toBytes);
-            }
-        }
-    }
-
     @Override
     public void emitOverflowCheckBranch(LabelRef overflow, LabelRef noOverflow, LIRKind cmpLIRKind, double overflowProbability) {
         SPARCKind cmpKind = (SPARCKind) cmpLIRKind.getPlatformKind();
@@ -303,7 +278,7 @@
         }
         Variable result = newVariable(trueValue.getLIRKind());
         ConditionFlag finalCondition = SPARCControlFlow.fromCondition(cmpSPARCKind.isInteger(), mirrored ? cond.mirror() : cond, unorderedIsTrue);
-        CC cc = CC.forKind(toSPARCCmpKind(cmpSPARCKind));
+        CC cc = CC.forKind(cmpSPARCKind);
         append(new CondMoveOp(cmove, cc, finalCondition, actualTrueValue, actualFalseValue, result));
         return result;
     }
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeMatchRules.java	Tue Nov 03 13:30:53 2015 +0100
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeMatchRules.java	Tue Nov 03 18:14:26 2015 +0100
@@ -24,9 +24,9 @@
 package com.oracle.graal.compiler.sparc;
 
 import static jdk.vm.ci.sparc.SPARCKind.BYTE;
-import static jdk.vm.ci.sparc.SPARCKind.XWORD;
 import static jdk.vm.ci.sparc.SPARCKind.HWORD;
 import static jdk.vm.ci.sparc.SPARCKind.WORD;
+import static jdk.vm.ci.sparc.SPARCKind.XWORD;
 import jdk.vm.ci.common.JVMCIError;
 import jdk.vm.ci.meta.LIRKind;
 import jdk.vm.ci.meta.Value;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCSubIntCompareCanonicalizationPhase.java	Tue Nov 03 18:14:26 2015 +0100
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 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.sparc;
+
+import jdk.vm.ci.code.CodeUtil;
+import jdk.vm.ci.common.JVMCIError;
+import jdk.vm.ci.meta.JavaConstant;
+
+import com.oracle.graal.compiler.common.type.IntegerStamp;
+import com.oracle.graal.compiler.common.type.Stamp;
+import com.oracle.graal.graph.Node;
+import com.oracle.graal.nodes.ConstantNode;
+import com.oracle.graal.nodes.StructuredGraph;
+import com.oracle.graal.nodes.ValueNode;
+import com.oracle.graal.nodes.calc.CompareNode;
+import com.oracle.graal.nodes.calc.SignExtendNode;
+import com.oracle.graal.phases.Phase;
+
+public class SPARCSubIntCompareCanonicalizationPhase extends Phase {
+    public SPARCSubIntCompareCanonicalizationPhase() {
+
+    }
+
+    @Override
+    protected void run(StructuredGraph graph) {
+        for (Node n : graph.getNodes()) {
+            if (n instanceof CompareNode) {
+                CompareNode enode = (CompareNode) n;
+                min32(enode, enode.getX());
+                min32(enode, enode.getY());
+            }
+        }
+    }
+
+    private static void min32(CompareNode enode, ValueNode v) {
+        Stamp s = v.stamp();
+        if (s instanceof IntegerStamp) {
+            int bits = ((IntegerStamp) s).getBits();
+            if (bits != 32 && bits != 64) {
+                if (bits <= 32) {
+                    bits = 32;
+                } else {
+                    bits = 64;
+                }
+                ValueNode replacement;
+                if (v instanceof ConstantNode) {
+                    JavaConstant newConst;
+                    if (bits == 32) {
+                        newConst = JavaConstant.forInt(v.asJavaConstant().asInt());
+                    } else if (bits == 64) {
+                        newConst = JavaConstant.forLong(v.asJavaConstant().asLong());
+                    } else {
+                        throw JVMCIError.shouldNotReachHere();
+                    }
+                    long mask = CodeUtil.mask(bits);
+                    replacement = v.graph().addOrUnique(new ConstantNode(newConst, IntegerStamp.stampForMask(bits, newConst.asLong() & mask, newConst.asLong() & mask)));
+                } else {
+                    replacement = v.graph().addOrUnique(new SignExtendNode(v, bits));
+                }
+                v.replaceAtUsages(replacement, x -> x == enode);
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCSuitesProvider.java	Tue Nov 03 18:14:26 2015 +0100
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 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.sparc;
+
+import java.util.ListIterator;
+
+import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
+import com.oracle.graal.java.DefaultSuitesProvider;
+import com.oracle.graal.phases.BasePhase;
+import com.oracle.graal.phases.common.LoweringPhase;
+import com.oracle.graal.phases.tiers.CompilerConfiguration;
+import com.oracle.graal.phases.tiers.LowTierContext;
+import com.oracle.graal.phases.tiers.Suites;
+
+public class SPARCSuitesProvider extends DefaultSuitesProvider {
+    public SPARCSuitesProvider(CompilerConfiguration compilerConfiguration, Plugins plugins) {
+        super(compilerConfiguration, plugins);
+    }
+
+    @Override
+    public Suites createSuites() {
+        Suites s = super.createSuites();
+        ListIterator<BasePhase<? super LowTierContext>> it = s.getLowTier().findPhase(LoweringPhase.class);
+        it.add(new SPARCSubIntCompareCanonicalizationPhase());
+        return s;
+    }
+}
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java	Tue Nov 03 13:30:53 2015 +0100
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java	Tue Nov 03 18:14:26 2015 +0100
@@ -41,6 +41,7 @@
 import jdk.vm.ci.sparc.SPARC;
 
 import com.oracle.graal.compiler.sparc.SPARCAddressLowering;
+import com.oracle.graal.compiler.sparc.SPARCSuitesProvider;
 import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
 import com.oracle.graal.hotspot.DefaultHotSpotGraalCompilerFactory;
 import com.oracle.graal.hotspot.HotSpotBackend;
@@ -58,7 +59,6 @@
 import com.oracle.graal.hotspot.meta.HotSpotStampProvider;
 import com.oracle.graal.hotspot.meta.HotSpotSuitesProvider;
 import com.oracle.graal.hotspot.word.HotSpotWordTypes;
-import com.oracle.graal.java.DefaultSuitesProvider;
 import com.oracle.graal.nodes.spi.LoweringProvider;
 import com.oracle.graal.phases.tiers.CompilerConfiguration;
 import com.oracle.graal.phases.util.Providers;
@@ -108,7 +108,7 @@
     }
 
     protected HotSpotSuitesProvider createSuites(HotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration, Plugins plugins, CodeCacheProvider codeCache) {
-        return new HotSpotSuitesProvider(new DefaultSuitesProvider(compilerConfiguration, plugins), config, runtime, new SPARCAddressLowering(codeCache));
+        return new HotSpotSuitesProvider(new SPARCSuitesProvider(compilerConfiguration, plugins), config, runtime, new SPARCAddressLowering(codeCache));
     }
 
     protected SPARCHotSpotBackend createBackend(HotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) {
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java	Tue Nov 03 13:30:53 2015 +0100
+++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java	Tue Nov 03 18:14:26 2015 +0100
@@ -179,7 +179,6 @@
                 }
                 if (!emitted) { // No short compare/branch was used, so we go into fallback
                     emitted = emitLongCompareBranch(crb, masm, true);
-                    masm.nop();
                     emitted = true;
                 }
             }
--- a/mx.graal/suite.py	Tue Nov 03 13:30:53 2015 +0100
+++ b/mx.graal/suite.py	Tue Nov 03 18:14:26 2015 +0100
@@ -733,7 +733,8 @@
       "sourceDirs" : ["src"],
       "dependencies" : [
         "com.oracle.graal.compiler",
-        "com.oracle.graal.lir.sparc"
+        "com.oracle.graal.lir.sparc",
+        "com.oracle.graal.java"
       ],
       "checkstyle" : "com.oracle.graal.graph",
       "annotationProcessors" : deps([
@@ -748,7 +749,7 @@
       "subDir" : "graal",
       "sourceDirs" : ["src"],
       "dependencies" : deps([
-        "com.oracle.graal.compiler.test",
+        "com.oracle.graal.lir.jtt",
         "jvmci:JVMCI_HOTSPOT"
       ]),
       "checkstyle" : "com.oracle.graal.graph",