|
32 | 32 | import static jdk.vm.ci.code.ValueUtil.isRegister; |
33 | 33 | import static jdk.vm.ci.code.ValueUtil.isStackSlot; |
34 | 34 |
|
| 35 | +import jdk.vm.ci.code.Register; |
35 | 36 | import org.graalvm.compiler.core.common.NumUtil; |
36 | 37 | import org.graalvm.compiler.asm.amd64.AMD64Address; |
37 | 38 | import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic; |
@@ -218,23 +219,39 @@ public static class ConstOp extends AMD64LIRInstruction { |
218 | 219 | @Def({REG, HINT}) protected AllocatableValue result; |
219 | 220 | @Use({REG}) protected AllocatableValue x; |
220 | 221 | private final int y; |
| 222 | + private final boolean setFlags; |
221 | 223 |
|
222 | | - public ConstOp(AMD64BinaryArithmetic opcode, OperandSize size, AllocatableValue result, AllocatableValue x, int y) { |
223 | | - this(opcode.getMIOpcode(size, NumUtil.isByte(y)), size, result, x, y); |
| 224 | + public ConstOp(AMD64BinaryArithmetic opcode, OperandSize size, AllocatableValue result, AllocatableValue x, int y, boolean setFlags) { |
| 225 | + this(opcode.getMIOpcode(size, NumUtil.isByte(y)), size, result, x, y, setFlags); |
224 | 226 | } |
225 | 227 |
|
226 | | - public ConstOp(AMD64MIOp opcode, OperandSize size, AllocatableValue result, AllocatableValue x, int y) { |
| 228 | + public ConstOp(AMD64MIOp opcode, OperandSize size, AllocatableValue result, AllocatableValue x, int y, boolean setFlags) { |
227 | 229 | super(TYPE); |
228 | 230 | this.opcode = opcode; |
229 | 231 | this.size = size; |
230 | 232 |
|
231 | 233 | this.result = result; |
232 | 234 | this.x = x; |
233 | 235 | this.y = y; |
| 236 | + this.setFlags = setFlags; |
234 | 237 | } |
235 | 238 |
|
236 | 239 | @Override |
237 | 240 | public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
| 241 | + if (!setFlags && isRegister(result) && isRegister(x) && !result.equals(x)) { |
| 242 | + if (opcode.toString().equals("ADD")) { |
| 243 | + masm.leaq(asRegister(result), new AMD64Address(asRegister(x), y)); |
| 244 | + return; |
| 245 | + } |
| 246 | + if (opcode.toString().equals("SUB")) { |
| 247 | + masm.leaq(asRegister(result), new AMD64Address(asRegister(x), -y)); |
| 248 | + return; |
| 249 | + } |
| 250 | + if (opcode.toString().equals("SHL") && y >= 1 && y <= 3) { |
| 251 | + masm.leaq(asRegister(result), new AMD64Address(Register.None, asRegister(x), AMD64Address.Scale.fromShift(y))); |
| 252 | + return; |
| 253 | + } |
| 254 | + } |
238 | 255 | AMD64Move.move(crb, masm, result, x); |
239 | 256 | opcode.emit(masm, size, asRegister(result), y); |
240 | 257 | } |
|
0 commit comments