changeset 15038:5f6603f00e49

minor sign/zero extension tweaks
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 08 Apr 2014 20:13:59 -0700
parents c47ff5fd532f
children 631ca3972292
files graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/AndNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java
diffstat 3 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java	Tue Apr 08 20:13:15 2014 -0700
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java	Tue Apr 08 20:13:59 2014 -0700
@@ -353,10 +353,10 @@
     }
 
     @Override
-    public Value emitZeroExtendMemory(int inputBits, int resultBits, Access access) {
-        assert resultBits == 32 || resultBits == 64;
+    public Value emitZeroExtendMemory(int fromBits, int toBits, Access access) {
+        assert fromBits != toBits;
         Kind memoryKind = access.accessLocation().getValueKind();
-        if (memoryKind.getBitCount() != inputBits && !memoryKind.isUnsigned()) {
+        if (memoryKind.getBitCount() != fromBits && !memoryKind.isUnsigned()) {
             // The memory being read from is signed and smaller than the result size so
             // this is a sign extension to inputBits followed by a zero extension to resultBits
             // which can't be expressed in a memory operation.
@@ -366,7 +366,7 @@
             memoryKind = Kind.Char;
         }
         evaluateDeferred();
-        return gen.getLIRGenerator().emitZeroExtendMemory(memoryKind, resultBits, makeAddress(access), getState(access));
+        return gen.getLIRGenerator().emitZeroExtendMemory(memoryKind, toBits, makeAddress(access), getState(access));
     }
 
     public boolean emitIfMemory(IfNode x, Access access) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/AndNode.java	Tue Apr 08 20:13:15 2014 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/AndNode.java	Tue Apr 08 20:13:59 2014 -0700
@@ -67,6 +67,13 @@
             if ((rawY & mask) == 0) {
                 return ConstantNode.forIntegerStamp(stamp(), 0, graph());
             }
+            if (x() instanceof SignExtendNode) {
+                SignExtendNode ext = (SignExtendNode) x();
+                if (rawY == ((1L << ext.getInputBits()) - 1)) {
+                    ValueNode result = graph().unique(new ZeroExtendNode(ext.getInput(), ext.getResultBits()));
+                    return result;
+                }
+            }
             if (x().stamp() instanceof IntegerStamp) {
                 IntegerStamp xStamp = (IntegerStamp) x().stamp();
                 if (((xStamp.upMask() | xStamp.downMask()) & ~rawY) == 0) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java	Tue Apr 08 20:13:15 2014 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java	Tue Apr 08 20:13:59 2014 -0700
@@ -75,6 +75,19 @@
             ZeroExtendNode other = (ZeroExtendNode) getInput();
             return graph().unique(new ZeroExtendNode(other.getInput(), getResultBits()));
         }
+        if (getInput() instanceof NarrowNode) {
+            NarrowNode narrow = (NarrowNode) getInput();
+            Stamp inputStamp = narrow.getInput().stamp();
+            if (inputStamp instanceof IntegerStamp && inputStamp.isCompatible(stamp())) {
+                IntegerStamp istamp = (IntegerStamp) inputStamp;
+                long mask = IntegerStamp.defaultMask(PrimitiveStamp.getBits(narrow.stamp()));
+                if (((istamp.upMask() | istamp.downMask()) & ~mask) == 0) {
+                    // The original value is in the range of the masked zero extended result so
+                    // simply return the original input.
+                    return narrow.getInput();
+                }
+            }
+        }
 
         return this;
     }