Skip to content

Commit

Permalink
[GR-57104] Use r12 as zero value register where applicable.
Browse files Browse the repository at this point in the history
PullRequest: graal/18684
  • Loading branch information
mur47x111 committed Sep 9, 2024
2 parents 5f0306c + abef2e2 commit df398bc
Show file tree
Hide file tree
Showing 33 changed files with 242 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ public static class AMD64MROp extends AMD64RROp {
// @formatter:off
public static final AMD64MROp MOVB = new AMD64MROp("MOVB", 0x88, OpAssertion.ByteAssertion);
public static final AMD64MROp MOV = new AMD64MROp("MOV", 0x89, OpAssertion.WordOrLargerAssertion);
// @formatter:on
public static final AMD64MROp TEST = new AMD64MROp("TEST", 0x85, OpAssertion.WordOrLargerAssertion);
// @formatter:on

protected AMD64MROp(String opcode, int op, OpAssertion assertion) {
this(opcode, 0, 0, op, assertion, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public final void movdbl(AMD64Address dst, Register src) {
*/
public final void movlong(AMD64Address dst, long src) {
if (NumUtil.isInt(src)) {
AMD64MIOp.MOV.emit(this, OperandSize.QWORD, dst, (int) src);
emitAMD64MIOp(AMD64MIOp.MOV, OperandSize.QWORD, dst, (int) src, false);
} else {
AMD64Address high = new AMD64Address(dst.getBase(), dst.getIndex(), dst.getScale(), dst.getDisplacement() + 4, dst.getDisplacementAnnotation(), dst.instructionStartPosition);
movl(dst, (int) (src & 0xFFFFFFFF));
Expand Down Expand Up @@ -1439,4 +1439,79 @@ public final void ptestU(AVXKind.AVXSize size, Register dst, AMD64Address src, R
public boolean isAVX() {
return supports(CPUFeature.AVX);
}

public final void moveInt(Register dst, int imm) {
if (imm == 0) {
Register zeroValueRegister = getZeroValueRegister();
if (!Register.None.equals(zeroValueRegister)) {
movl(dst, zeroValueRegister);
return;
}
}
movl(dst, imm);
}

public final void moveInt(AMD64Address dst, int imm) {
if (imm == 0) {
Register zeroValueRegister = getZeroValueRegister();
if (!Register.None.equals(zeroValueRegister)) {
movl(dst, zeroValueRegister);
return;
}
}
movl(dst, imm);
}

public final void moveIntSignExtend(Register result, int imm) {
if (imm == 0) {
Register zeroValueRegister = getZeroValueRegister();
if (!Register.None.equals(zeroValueRegister)) {
movl(result, zeroValueRegister);
return;
}
}
movslq(result, imm);
}

private static AMD64MROp toMR(AMD64MIOp op) {
if (op == AMD64MIOp.MOVB) {
return AMD64MROp.MOVB;
} else if (op == AMD64MIOp.MOV) {
return AMD64MROp.MOV;
} else if (op == AMD64MIOp.TEST) {
return AMD64MROp.TEST;
}
return null;
}

public final void emitAMD64MIOp(AMD64MIOp opcode, OperandSize size, Register dst, int imm, boolean annotateImm) {
if (imm == 0) {
Register zeroValueRegister = getZeroValueRegister();
AMD64MROp mrOp = toMR(opcode);
if (!Register.None.equals(zeroValueRegister) && mrOp != null) {
mrOp.emit(this, size, dst, zeroValueRegister);
return;
}
}
opcode.emit(this, size, dst, imm, annotateImm);
}

public final void emitAMD64MIOp(AMD64MIOp opcode, OperandSize size, AMD64Address dst, int imm, boolean annotateImm) {
if (imm == 0) {
Register zeroValueRegister = getZeroValueRegister();
AMD64MROp mrOp = toMR(opcode);
if (!Register.None.equals(zeroValueRegister) && mrOp != null) {
mrOp.emit(this, size, dst, zeroValueRegister);
return;
}
}
opcode.emit(this, size, dst, imm, annotateImm);
}

/**
* Returns a register whose content is always zero.
*/
public Register getZeroValueRegister() {
return Register.None;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -96,13 +96,15 @@
import jdk.vm.ci.code.RegisterConfig;
import jdk.vm.ci.code.RegisterValue;
import jdk.vm.ci.meta.AllocatableValue;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.DeoptimizationAction;
import jdk.vm.ci.meta.DeoptimizationReason;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.PlatformKind;
import jdk.vm.ci.meta.SpeculationLog;
import jdk.vm.ci.meta.Value;
import jdk.vm.ci.meta.ValueKind;

/**
* LIR generator specialized for AMD64 HotSpot.
Expand Down Expand Up @@ -655,4 +657,15 @@ public int getArrayLengthOffset() {
public Register getHeapBaseRegister() {
return getProviders().getRegisters().getHeapBaseRegister();
}

@Override
public AllocatableValue emitLoadConstant(ValueKind<?> kind, Constant constant) {
if (((AMD64Kind) kind.getPlatformKind()).isInteger() && constant instanceof JavaConstant && constant.isDefaultForKind()) {
Register zeroValueRegister = getProviders().getRegisters().getZeroValueRegister(config);
if (!Register.None.equals(zeroValueRegister)) {
return zeroValueRegister.asValue(kind);
}
}
return super.emitLoadConstant(kind, constant);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -171,4 +171,9 @@ protected final int membarOffset() {
}
return offset;
}

@Override
public Register getZeroValueRegister() {
return providers.getRegisters().getZeroValueRegister(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AMD64HotSpotXAtomicReadAndWriteOp(Variable result, AMD64AddressValue load
@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
AMD64Move.move(QWORD, crb, masm, result, newValue);
masm.xchgq(asRegister(result), loadAddress.toAddress());
masm.xchgq(asRegister(result), loadAddress.toAddress(masm));
emitBarrier(crb, masm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected AMD64HotSpotXBarrieredOp(LIRInstructionClass<? extends AMD64HotSpotXBa
* Emit a barrier testing a specific register.
*/
protected void emitBarrier(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register register, Label success) {
AMD64HotSpotXBarrierSetLIRGenerator.emitBarrier(crb, masm, success, register, config, callTarget, loadAddress.toAddress(), this);
AMD64HotSpotXBarrierSetLIRGenerator.emitBarrier(crb, masm, success, register, config, callTarget, loadAddress.toAddress(masm), this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
if (crb.target.isMP) {
masm.lock();
}
masm.cmpxchgq(newReg, loadAddress.toAddress());
masm.cmpxchgq(newReg, loadAddress.toAddress(masm));
// if the cmpxchgq succeeds then we are done
masm.jccb(AMD64Assembler.ConditionFlag.Zero, success);
/*
Expand All @@ -91,7 +91,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
if (crb.target.isMP) {
masm.lock();
}
masm.cmpxchgq(newReg, loadAddress.toAddress());
masm.cmpxchgq(newReg, loadAddress.toAddress(masm));
masm.bind(barrierOk);
masm.cmpq(asRegister(temp), asRegister(result));
masm.bind(success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
crb.recordImplicitException(masm.position(), state);
}
final Register resultReg = asRegister(result);
MOV.emit(masm, AMD64BaseAssembler.OperandSize.QWORD, resultReg, loadAddress.toAddress());
MOV.emit(masm, AMD64BaseAssembler.OperandSize.QWORD, resultReg, loadAddress.toAddress(masm));
emitBarrier(crb, masm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
crb.recordImplicitException(masm.position(), state);
}
Register resultReg = asRegister(result);
op.emit(masm, size, resultReg, loadAddress.toAddress());
op.emit(masm, size, resultReg, loadAddress.toAddress(masm));

AMD64Address address = loadAddress.toAddress();
AMD64Address address = loadAddress.toAddress(masm);

final Label entryPoint = new Label();
final Label continuation = new Label();
Expand Down Expand Up @@ -119,7 +119,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
masm.movslq(cArg1, count);
AMD64Call.directCall(crb, masm, callTarget, null, false, null);
masm.movq(resultReg, cArg0);
op.emit(masm, size, resultReg, loadAddress.toAddress());
op.emit(masm, size, resultReg, loadAddress.toAddress(masm));

// Return to inline code
masm.jmp(continuation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public AMD64HotSpotZAtomicReadAndWriteOp(Variable result, AMD64AddressValue load
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
emitPreWriteBarrier(crb, masm, asRegister(result), null);
zColor(crb, masm, asRegister(result), asRegister(newValue));
masm.xchgq(asRegister(result), storeAddress.toAddress());
masm.xchgq(asRegister(result), storeAddress.toAddress(masm));
Register ref = asRegister(result);
AMD64HotSpotZBarrierSetLIRGenerator.zUncolor(crb, masm, ref);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
if (crb.target.isMP) {
masm.lock();
}
masm.cmpxchgq(asRegister(tmp), storeAddress.toAddress());
masm.cmpxchgq(asRegister(tmp), storeAddress.toAddress(masm));
if (!isLogic) {
Register ref = asRegister(cmpValue);
AMD64HotSpotZBarrierSetLIRGenerator.zUncolor(crb, masm, ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ protected AMD64HotSpotZLoadBarrieredOp(LIRInstructionClass<? extends AMD64HotSpo
* Emit a barrier testing the {@code result} register.
*/
protected void emitLoadBarrier(CompilationResultBuilder crb, AMD64MacroAssembler masm, boolean isNotStrong) {
AMD64HotSpotZBarrierSetLIRGenerator.emitLoadBarrier(crb, masm, asRegister(result), callTarget, loadAddress.toAddress(), this, isNotStrong);
AMD64HotSpotZBarrierSetLIRGenerator.emitLoadBarrier(crb, masm, asRegister(result), callTarget, loadAddress.toAddress(masm), this, isNotStrong);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
crb.recordImplicitException(masm.position(), state);
}
final Register resultReg = asRegister(result);
MOV.emit(masm, AMD64BaseAssembler.OperandSize.QWORD, resultReg, loadAddress.toAddress());
MOV.emit(masm, AMD64BaseAssembler.OperandSize.QWORD, resultReg, loadAddress.toAddress(masm));
emitLoadBarrier(crb, masm, isNotStrong);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected AMD64HotSpotZStoreBarrieredOp(LIRInstructionClass<? extends AMD64HotSp
}

protected void emitPreWriteBarrier(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register resultReg, LIRFrameState state) {
AMD64HotSpotZBarrierSetLIRGenerator.emitPreWriteBarrier(crb, masm, this, config, storeAddress.toAddress(), resultReg, storeKind, asRegister(tmp), asRegister(tmp2), callTarget,
AMD64HotSpotZBarrierSetLIRGenerator.emitPreWriteBarrier(crb, masm, this, config, storeAddress.toAddress(masm), resultReg, storeKind, asRegister(tmp), asRegister(tmp2), callTarget,
state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
crb.recordImplicitException(masm.position(), state);
}
Register resultReg = asRegister(result);
op.emit(masm, size, resultReg, loadAddress.toAddress());
op.emit(masm, size, resultReg, loadAddress.toAddress(masm));

AMD64Address address = loadAddress.toAddress();
AMD64Address address = loadAddress.toAddress(masm);

final Label entryPoint = new Label();
final Label continuation = new Label();
Expand Down Expand Up @@ -129,7 +129,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
masm.movslq(cArg1, count);
AMD64Call.directCall(crb, masm, callTarget, null, false, null);
masm.movq(resultReg, cArg0);
op.emit(masm, size, resultReg, loadAddress.toAddress());
op.emit(masm, size, resultReg, loadAddress.toAddress(masm));

// Return to inline code
masm.jmp(continuation);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,7 @@
*/
package jdk.graal.compiler.hotspot.meta;

import jdk.graal.compiler.hotspot.GraalHotSpotVMConfig;
import jdk.vm.ci.code.Register;

public class HotSpotRegisters implements HotSpotRegistersProvider {
Expand Down Expand Up @@ -55,4 +56,16 @@ public Register getStackPointerRegister() {
assert !stackPointerRegister.equals(Register.None) : "stack pointer register is not defined";
return stackPointerRegister;
}

@Override
public Register getZeroValueRegister(GraalHotSpotVMConfig config) {
if (config.useCompressedOops && !config.getOopEncoding().hasBase()) {
/*
* Heap base register is exempted from register allocation when using compressed oops.
* Its value will be config.getOopEncoding().getBase().
*/
return getHeapBaseRegister();
}
return Register.None;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,7 @@
*/
package jdk.graal.compiler.hotspot.meta;

import jdk.graal.compiler.hotspot.GraalHotSpotVMConfig;
import jdk.vm.ci.code.Register;

/**
Expand All @@ -45,4 +46,9 @@ public interface HotSpotRegistersProvider {
* Gets the stack pointer register.
*/
Register getStackPointerRegister();

/**
* Gets the register whose value is always 0.
*/
Register getZeroValueRegister(GraalHotSpotVMConfig config);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -34,7 +34,6 @@
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.lir.framemap.SimpleVirtualStackSlot;
import jdk.graal.compiler.lir.framemap.SimpleVirtualStackSlotAlias;

import jdk.vm.ci.code.Register;
import jdk.vm.ci.code.RegisterValue;
import jdk.vm.ci.code.StackSlot;
Expand Down
Loading

0 comments on commit df398bc

Please sign in to comment.