RFR: JDK-8323497: On x64, use 32-bit immediate moves for narrow klass base if possible
Aleksey Shipilev
shade at openjdk.org
Tue Jan 30 11:51:50 UTC 2024
On Wed, 10 Jan 2024 10:23:02 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> FYI the logic for immediate matching is:
>>
>> if (is_uimm32(imm)) {
>> movl(dst, imm);
>> } else if (is_simm32(imm)) {
>> movq(dst, imm);
>> } else {
>> mov64(dst, imm);
>> }
>>
>> The reason is that `movl` is smaller than `movq` in code size.
>>
>> Maybe we can change `movptr` to this. I hope that I do not miss anything here.
>
> Yeah, current `movptr` is sign-extending 32->64, which is not extra-efficient for 32-bit unsigned imms with highest bit set. I think we can indeed check for `is_uimm32` in `movptr` to cover that case too.
This seems to work:
diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp
index 88296656485..ba4b089c7aa 100644
--- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp
+++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp
@@ -2568,7 +2568,9 @@ void MacroAssembler::movptr(Register dst, Address src) {
// src should NEVER be a real pointer. Use AddressLiteral for true pointers
void MacroAssembler::movptr(Register dst, intptr_t src) {
#ifdef _LP64
- if (is_simm32(src)) {
+ if (is_uimm32(src)) {
+ movl(dst, checked_cast<uint32_t>(src));
+ } else if (is_simm32(src)) {
movq(dst, checked_cast<int32_t>(src));
} else {
mov64(dst, src);
diff --git a/src/hotspot/share/asm/assembler.hpp b/src/hotspot/share/asm/assembler.hpp
index 7b7dbd4ede7..a533b963844 100644
--- a/src/hotspot/share/asm/assembler.hpp
+++ b/src/hotspot/share/asm/assembler.hpp
@@ -359,6 +359,7 @@ class AbstractAssembler : public ResourceObj {
}
static bool is_uimm12(uint64_t x) { return is_uimm(x, 12); }
+ static bool is_uimm32(uint64_t x) { return is_uimm(x, 32); }
// Accessors
CodeSection* code_section() const { return _code_section; }
Does that work with all narrow klass bases now, @tstuefe?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17340#discussion_r1447200469
More information about the hotspot-dev
mailing list