Mercurial > hg > truffle
changeset 17218:43a89fe3ff8b
[SPARC] Eliminate sign extension when signed load is used
author | Stefan Anzinger <stefan.anzinger@oracle.com> |
---|---|
date | Thu, 25 Sep 2014 18:59:58 -0700 |
parents | 1738211d4cdb |
children | 44389818b25b |
files | graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeLIRBuilder.java |
diffstat | 1 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeLIRBuilder.java Thu Sep 25 18:54:59 2014 -0700 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeLIRBuilder.java Thu Sep 25 18:59:58 2014 -0700 @@ -25,12 +25,16 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.compiler.match.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.*; import com.oracle.graal.lir.gen.*; import com.oracle.graal.lir.sparc.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.extended.*; /** * This class implements the SPARC specific portion of the LIR generator. @@ -62,4 +66,54 @@ protected JumpOp newJumpOp(LabelRef ref) { return new SPARCJumpOp(ref); } + + protected LIRFrameState getState(Access access) { + if (access instanceof DeoptimizingNode) { + return state((DeoptimizingNode) access); + } + return null; + } + + private ComplexMatchResult emitSignExtendMemory(Access access, int fromBits, int toBits) { + assert fromBits <= toBits && toBits <= 64; + Kind toKind = null; + Kind fromKind = null; + if (fromBits == toBits) { + return null; + } else if (toBits > 32) { + toKind = Kind.Long; + } else if (toBits > 16) { + toKind = Kind.Int; + } else { + toKind = Kind.Short; + } + switch (fromBits) { + case 8: + fromKind = Kind.Byte; + break; + case 16: + fromKind = Kind.Short; + break; + case 32: + fromKind = Kind.Int; + break; + default: + throw GraalInternalError.unimplemented("unsupported sign extension (" + fromBits + " bit -> " + toBits + " bit)"); + } + { + Kind localFromKind = fromKind; + Kind localToKind = toKind; + return builder -> { + Value address = access.accessLocation().generateAddress(builder, gen, operand(access.object())); + Value v = getLIRGeneratorTool().emitLoad(LIRKind.value(localFromKind), address, getState(access)); + return getLIRGeneratorTool().emitReinterpret(LIRKind.value(localToKind), v); + }; + } + } + + @MatchRule("(SignExtend Read=access)") + @MatchRule("(SignExtend FloatingRead=access)") + public ComplexMatchResult removeSignExtend(SignExtendNode root, Access access) { + return emitSignExtendMemory(access, root.getInputBits(), root.getResultBits()); + } }