Mercurial > hg > graal-jvmci-8
changeset 13466:51d31106cd5e
fix wrong register definition in AMD64 TableSwitchOp
author | Erik Eckstein <erik.eckstein@oracle.com> |
---|---|
date | Fri, 20 Dec 2013 08:06:48 +0100 |
parents | e2a14719e833 |
children | 7c694e3e97e5 |
files | graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java |
diffstat | 2 files changed, 16 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Thu Dec 19 11:42:16 2013 +0100 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Fri Dec 20 08:06:48 2013 +0100 @@ -988,10 +988,7 @@ @Override protected void emitTableSwitch(int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value key) { - // Making a copy of the switch value is necessary because jump table destroys the input - // value - Variable tmp = emitMove(key); - append(new TableSwitchOp(lowKey, defaultTarget, targets, tmp, newVariable(target().wordKind))); + append(new TableSwitchOp(lowKey, defaultTarget, targets, key, newVariable(target().wordKind), newVariable(key.getPlatformKind()))); } @Override
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Thu Dec 19 11:42:16 2013 +0100 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Fri Dec 20 08:06:48 2013 +0100 @@ -161,31 +161,38 @@ private final int lowKey; private final LabelRef defaultTarget; private final LabelRef[] targets; - @Alive protected Value index; + @Use protected Value index; + @Temp({REG, HINT}) protected Value idxScratch; @Temp protected Value scratch; - public TableSwitchOp(final int lowKey, final LabelRef defaultTarget, final LabelRef[] targets, Variable index, Variable scratch) { + public TableSwitchOp(final int lowKey, final LabelRef defaultTarget, final LabelRef[] targets, Value index, Variable scratch, Variable idxScratch) { this.lowKey = lowKey; this.defaultTarget = defaultTarget; this.targets = targets; this.index = index; this.scratch = scratch; + this.idxScratch = idxScratch; } @Override public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { - Register value = asIntReg(index); + Register indexReg = asIntReg(index); + Register idxScratchReg = asIntReg(idxScratch); Register scratchReg = asLongReg(scratch); + if (!indexReg.equals(idxScratchReg)) { + masm.movl(idxScratchReg, indexReg); + } + Buffer buf = masm.codeBuffer; // Compare index against jump table bounds int highKey = lowKey + targets.length - 1; if (lowKey != 0) { // subtract the low value from the switch value - masm.subl(value, lowKey); - masm.cmpl(value, highKey - lowKey); + masm.subl(idxScratchReg, lowKey); + masm.cmpl(idxScratchReg, highKey - lowKey); } else { - masm.cmpl(value, highKey); + masm.cmpl(idxScratchReg, highKey); } // Jump to default target if index is not within the jump table @@ -199,8 +206,8 @@ int afterLea = buf.position(); // Load jump table entry into scratch and jump to it - masm.movslq(value, new AMD64Address(scratchReg, value, Scale.Times4, 0)); - masm.addq(scratchReg, value); + masm.movslq(idxScratchReg, new AMD64Address(scratchReg, idxScratchReg, Scale.Times4, 0)); + masm.addq(scratchReg, idxScratchReg); masm.jmp(scratchReg); // Inserting padding so that jump table address is 4-byte aligned