# HG changeset patch # User Tom Rodriguez # Date 1397013239 25200 # Node ID 5f6603f00e4957b6628407d3b1033e5d20fa7015 # Parent c47ff5fd532fc9d2d8e9eb12477a11a6528e2a91 minor sign/zero extension tweaks diff -r c47ff5fd532f -r 5f6603f00e49 graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java --- 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) { diff -r c47ff5fd532f -r 5f6603f00e49 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/AndNode.java --- 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) { diff -r c47ff5fd532f -r 5f6603f00e49 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java --- 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; }