changeset 3467:d007292cdb70

Use IsNotNull even for comparison against null, fix for wrong filtered class in LoopBegin.dataUsages
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Thu, 28 Jul 2011 11:33:23 +0200
parents 28071fae8577
children 6c5242cd8930
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoopBegin.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MaterializeNode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/NegateBooleanNode.java
diffstat 5 files changed, 66 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jul 27 15:44:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Thu Jul 28 11:33:23 2011 +0200
@@ -504,9 +504,11 @@
         lir.branch(cond, trueSuccessor);
     }
 
-    public void emitBooleanBranch(Node node, LIRBlock trueSuccessor, LIRBlock falseSuccessor, LIRDebugInfo info) {
+    public void emitBooleanBranch(BooleanNode node, LIRBlock trueSuccessor, LIRBlock falseSuccessor, LIRDebugInfo info) {
         if (node instanceof NegateBooleanNode) {
             emitBooleanBranch(((NegateBooleanNode) node).value(), falseSuccessor, trueSuccessor, info);
+        } else if (node instanceof IsNonNull) {
+            emitIsNonNullBranch((IsNonNull) node, trueSuccessor, falseSuccessor);
         } else if (node instanceof Compare) {
             emitCompare((Compare) node, trueSuccessor, falseSuccessor);
         } else if (node instanceof InstanceOf) {
@@ -518,6 +520,25 @@
         }
     }
 
+    private void emitIsNonNullBranch(IsNonNull node, LIRBlock trueSuccessor, LIRBlock falseSuccessor) {
+        Condition cond = Condition.NE;
+        if (trueSuccessor == null) {
+            cond = cond.negate();
+            trueSuccessor = falseSuccessor;
+            falseSuccessor = null;
+        }
+
+        LIRItem xitem = new LIRItem(node.object(), this);
+        xitem.loadItem();
+
+        lir.cmp(cond, xitem.result(), CiConstant.NULL_OBJECT);
+        lir.branch(cond, trueSuccessor);
+
+        if (falseSuccessor != null) {
+            lir.jump(falseSuccessor);
+        }
+    }
+
     private void emitInstanceOf(TypeCheck x, LIRBlock trueSuccessor, LIRBlock falseSuccessor, LIRDebugInfo info) {
         XirArgument obj = toXirArgument(x.object());
         XirSnippet snippet = xir.genInstanceOf(site(x), obj, toXirArgument(x.targetClassInstruction()), x.targetClass());
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java	Wed Jul 27 15:44:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java	Thu Jul 28 11:33:23 2011 +0200
@@ -170,7 +170,12 @@
         @Override
         public Node canonical(Node node) {
             Compare compare = (Compare) node;
-            if (compare.x().isConstant() && compare.y().isConstant()) {
+            if (compare.x().isConstant() && !compare.y().isConstant()) { // move constants to the left (y)
+                Value x = compare.x();
+                compare.setX(compare.y());
+                compare.setY(x);
+                compare.condition = compare.condition.mirror();
+            } else if (compare.x().isConstant() && compare.y().isConstant()) {
                 CiConstant constX = compare.x().asConstant();
                 CiConstant constY = compare.y().asConstant();
                 Boolean result = compare.condition().foldCondition(constX, constY, ((CompilerGraph) node.graph()).runtime());
@@ -184,18 +189,36 @@
                         TTY.println("if not removed %s %s %s (%s %s)", constX, compare.condition(), constY, constX.kind, constY.kind);
                     }
                 }
-            } else if (compare.x().isConstant() && compare.y() instanceof MaterializeNode) {
-                return optimizeMaterialize(compare, compare.x().asConstant(), (MaterializeNode) compare.y());
-            } else if (compare.y().isConstant() && compare.x() instanceof MaterializeNode) {
-                return optimizeMaterialize(compare, compare.y().asConstant(), (MaterializeNode) compare.x());
-            } else if (compare.x().isConstant() && compare.y() instanceof NormalizeCompare) {
-                return optimizeNormalizeCmp(compare, compare.x().asConstant(), (NormalizeCompare) compare.y());
-            } else if (compare.y().isConstant() && compare.x() instanceof NormalizeCompare) {
-                return optimizeNormalizeCmp(compare, compare.y().asConstant(), (NormalizeCompare) compare.x());
             }
-            if ((compare.x() == compare.y() || compare.x().valueEqual(compare.y())) && compare.x().kind != CiKind.Float && compare.x().kind != CiKind.Double) {
+
+            if (compare.y().isConstant()) {
+                if (compare.x() instanceof MaterializeNode) {
+                    return optimizeMaterialize(compare, compare.y().asConstant(), (MaterializeNode) compare.x());
+                } else if (compare.x() instanceof NormalizeCompare) {
+                    return optimizeNormalizeCmp(compare, compare.y().asConstant(), (NormalizeCompare) compare.x());
+                }
+            }
+
+            if (compare.x() == compare.y() && compare.x().kind != CiKind.Float && compare.x().kind != CiKind.Double) {
                 return Constant.forBoolean(compare.condition().check(1, 1), compare.graph());
             }
+            if ((compare.condition == Condition.NE || compare.condition == Condition.EQ) && compare.x().kind == CiKind.Object) {
+                Value object = null;
+                if (compare.x().isNullConstant()) {
+                    object = compare.y();
+                } else if (compare.y().isNullConstant()) {
+                    object = compare.x();
+                }
+                if (object != null) {
+                    IsNonNull nonNull =  new IsNonNull(object, compare.graph());
+                    if (compare.condition == Condition.NE) {
+                        return nonNull;
+                    } else {
+                        assert compare.condition == Condition.EQ;
+                        return new NegateBooleanNode(nonNull, compare.graph());
+                    }
+                }
+            }
             return compare;
         }
 
@@ -206,7 +229,7 @@
                     if (compare.condition == Condition.NE) {
                         isFalseCheck = !isFalseCheck;
                     }
-                    Value result = materializeNode.value();
+                    BooleanNode result = materializeNode.value();
                     if (isFalseCheck) {
                         result = new NegateBooleanNode(result, compare.graph());
                     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoopBegin.java	Wed Jul 27 15:44:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoopBegin.java	Thu Jul 28 11:33:23 2011 +0200
@@ -142,7 +142,7 @@
         return new Iterable<Node>() {
             @Override
             public Iterator<Node> iterator() {
-                return new StateSplit.FilteringIterator(dataUsages, LoopBegin.class);
+                return new StateSplit.FilteringIterator(dataUsages, LoopEnd.class);
             }
         };
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MaterializeNode.java	Wed Jul 27 15:44:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MaterializeNode.java	Thu Jul 28 11:33:23 2011 +0200
@@ -49,15 +49,15 @@
     /**
      * The instruction which produces the input value to this instruction.
      */
-     public Value value() {
-        return (Value) inputs().get(super.inputCount() + INPUT_VALUE);
+     public BooleanNode value() {
+        return (BooleanNode) inputs().get(super.inputCount() + INPUT_VALUE);
     }
 
-    public void setValue(Value n) {
+    public void setValue(BooleanNode n) {
         inputs().set(super.inputCount() + INPUT_VALUE, n);
     }
 
-    public MaterializeNode(Value value, Graph graph) {
+    public MaterializeNode(BooleanNode value, Graph graph) {
         super(CiKind.Int, INPUT_COUNT, SUCCESSOR_COUNT, graph);
         setValue(value);
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/NegateBooleanNode.java	Wed Jul 27 15:44:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/NegateBooleanNode.java	Thu Jul 28 11:33:23 2011 +0200
@@ -46,15 +46,15 @@
     /**
      * The instruction that produces the array object.
      */
-     public Value value() {
-        return (Value) inputs().get(super.inputCount() + INPUT_NODE);
+     public BooleanNode value() {
+        return (BooleanNode) inputs().get(super.inputCount() + INPUT_NODE);
     }
 
-    public Value setValue(Value n) {
-        return (Value) inputs().set(super.inputCount() + INPUT_NODE, n);
+    public BooleanNode setValue(BooleanNode n) {
+        return (BooleanNode) inputs().set(super.inputCount() + INPUT_NODE, n);
     }
 
-    public NegateBooleanNode(Value value, Graph graph) {
+    public NegateBooleanNode(BooleanNode value, Graph graph) {
         super(CiKind.Int, INPUT_COUNT, SUCCESSOR_COUNT, graph);
         setValue(value);
     }