changeset 9448:7b88c5e5cbd4

Add more canonicalizations for Compare and Negate nodes
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 30 Apr 2013 20:07:07 +0200
parents 6160dc257c79
children 3d309a26d4d5
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractBeginNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractEndNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConvertNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NegateNode.java
diffstat 3 files changed, 50 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java	Tue Apr 30 20:05:21 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java	Tue Apr 30 20:07:07 2013 +0200
@@ -101,6 +101,16 @@
         return this;
     }
 
+    protected void setX(ValueNode x) {
+        updateUsages(this.x, x);
+        this.x = x;
+    }
+
+    protected void setY(ValueNode y) {
+        updateUsages(this.y, y);
+        this.y = y;
+    }
+
     protected LogicNode optimizeNormalizeCmp(Constant constant, NormalizeCompareNode normalizeNode, boolean mirrored) {
         throw new GraalInternalError("NormalizeCompareNode connected to %s (%s %s %s)", this, constant, normalizeNode, mirrored);
     }
@@ -123,6 +133,14 @@
                 return optimizeNormalizeCmp(y().asConstant(), (NormalizeCompareNode) x(), false);
             }
         }
+        if (x() instanceof ConvertNode && y() instanceof ConvertNode) {
+            ConvertNode convertX = (ConvertNode) x();
+            ConvertNode convertY = (ConvertNode) y();
+            if (convertX.opcode.isLossless() && convertY.opcode.isLossless()) {
+                setX(convertX.value());
+                setY(convertY.value());
+            }
+        }
         return this;
     }
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConvertNode.java	Tue Apr 30 20:05:21 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConvertNode.java	Tue Apr 30 20:07:07 2013 +0200
@@ -35,34 +35,40 @@
  */
 public final class ConvertNode extends FloatingNode implements Canonicalizable, LIRLowerable, Lowerable {
 
-    public enum Op {
-        I2L(Int, Long),
-        L2I(Long, Int),
-        I2B(Int, Byte),
-        I2C(Int, Char),
-        I2S(Int, Short),
-        F2D(Float, Double),
-        D2F(Double, Float),
-        I2F(Int, Float),
-        I2D(Int, Double),
-        F2I(Float, Int),
-        D2I(Double, Int),
-        L2F(Long, Float),
-        L2D(Long, Double),
-        F2L(Float, Long),
-        D2L(Double, Long),
-        UNSIGNED_I2L(Int, Long),
-        MOV_I2F(Int, Float),
-        MOV_L2D(Long, Double),
-        MOV_F2I(Float, Int),
-        MOV_D2L(Double, Long);
+    public static enum Op {
+        I2L(Int, Long, true),
+        L2I(Long, Int, false),
+        I2B(Int, Byte, false),
+        I2C(Int, Char, false),
+        I2S(Int, Short, false),
+        F2D(Float, Double, false),
+        D2F(Double, Float, false),
+        I2F(Int, Float, false),
+        I2D(Int, Double, true),
+        F2I(Float, Int, false),
+        D2I(Double, Int, false),
+        L2F(Long, Float, false),
+        L2D(Long, Double, false),
+        F2L(Float, Long, false),
+        D2L(Double, Long, false),
+        UNSIGNED_I2L(Int, Long, true),
+        MOV_I2F(Int, Float, false),
+        MOV_L2D(Long, Double, false),
+        MOV_F2I(Float, Int, false),
+        MOV_D2L(Double, Long, false);
 
         public final Kind from;
         public final Kind to;
+        public final boolean lossless;
 
-        private Op(Kind from, Kind to) {
+        private Op(Kind from, Kind to, boolean lossless) {
             this.from = from;
             this.to = to;
+            this.lossless = lossless;
+        }
+
+        public boolean isLossless() {
+            return lossless;
         }
 
         public static Op getOp(Kind from, Kind to) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NegateNode.java	Tue Apr 30 20:05:21 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NegateNode.java	Tue Apr 30 20:07:07 2013 +0200
@@ -69,6 +69,10 @@
         if (x() instanceof NegateNode) {
             return ((NegateNode) x()).x();
         }
+        if (x() instanceof IntegerSubNode) {
+            IntegerSubNode sub = (IntegerSubNode) x;
+            return IntegerArithmeticNode.sub(sub.y(), sub.x());
+        }
         return this;
     }