changeset 5606:5ad40c8ba3ed

add StampFactory.negate(IntegerStamp), use it for NegateNode
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 13 Jun 2012 13:40:39 +0200
parents 300a1207f214
children 168a00aa1e9e
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NegateNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NegateNode.java	Wed Jun 13 11:10:57 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NegateNode.java	Wed Jun 13 13:40:39 2012 +0200
@@ -38,12 +38,12 @@
     }
 
     /**
-     * Creates new NegateOp instance.
+     * Creates new NegateNode instance.
      *
      * @param x the instruction producing the value that is input to this instruction
      */
     public NegateNode(ValueNode x) {
-        super(StampFactory.forKind(x.kind()));
+        super(x.stamp() instanceof IntegerStamp ? StampFactory.negate((IntegerStamp) x.stamp()) : StampFactory.forKind(x.kind()));
         this.x = x;
     }
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java	Wed Jun 13 11:10:57 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java	Wed Jun 13 13:40:39 2012 +0200
@@ -129,6 +129,14 @@
         }
     }
 
+    public static Stamp negate(IntegerStamp stamp) {
+        Kind kind = stamp.kind();
+        if (stamp.lowerBound() != kind.minValue()) {
+            return new IntegerStamp(kind, -stamp.upperBound(), -stamp.lowerBound());
+        }
+        return forKind(kind);
+    }
+
     public static Stamp object() {
         return objectStamp;
     }