RFR: 8323503: x86: Shorter movptr(reg, imm) for 32-bit unsigned immediates
Vladimir Kozlov
kvn at openjdk.org
Wed Jan 10 20:57:22 UTC 2024
On Wed, 10 Jan 2024 11:05:03 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
> We noticed in [JDK-8323497](https://bugs.openjdk.org/browse/JDK-8323497) that `movptr` optimization done in [JDK-8319406](https://bugs.openjdk.org/browse/JDK-8319406) is not covering the case of immediates that fit in 32-bit unsigned, but do not fit in 32-bit signed. In that case, we can maybe do `mov r32, imm32` and rely on x86 zero-extending 32->64 bit for us. Since `movl` encoding is smaller than sign-extending `movq`, we also save more code on most paths that [JDK-8319406](https://bugs.openjdk.org/browse/JDK-8319406) improved.
>
> There are a few interesting conversions along the way:
> 1. `intptr_t` -> `uint32_t` (this method)
> 2. `uint32_t` -> `int32_t` (argument conversion for `movl`)
> 3. `int32_t` -> `uint32_t` (in `emit_int32`)
>
> I believe these are safe after `is_uimm32` check, but please check (sic) me on this.
>
> Note that x86_64 matcher already does similar thing for immediates:
>
>
> // Long Immediate 32-bit unsigned
> operand immUL32()
> %{
> predicate(n->get_long() == (unsigned int) (n->get_long()));
> match(ConL);
> ...
> %}
>
> instruct loadConUL32(rRegL dst, immUL32 src)
> %{
> ...
> format %{ "movl $dst, $src\t# long (unsigned 32-bit)" %}
> ins_encode %{
> __ movl($dst$$Register, $src$$constant);
> %}
> %}
>
>
> Additional testing:
> - [x] Linux x86_64 server fastdebug, `tier{1,2,3,4}`
>
> Code sizes for `Hello World`, `-Xcomp`:
>
>
> # Before
> tier1 nmethod code size : 426208 bytes
> tier2 nmethod code size : 462880 bytes
> tier3 nmethod code size : 889992 bytes
> tier4 nmethod code size : 1244448 bytes
>
> # After
> tier1 nmethod code size : 425768 bytes (-0.1%)
> tier2 nmethod code size : 462400 bytes (-0.1%)
> tier3 nmethod code size : 882072 bytes (-0.8%)
> tier4 nmethod code size : 1236448 bytes (-0.6%)
What about next?:
// src should NEVER be a real pointer. Use AddressLiteral for true pointers
void MacroAssembler::movptr(Address dst, intptr_t src, Register rscratch) {
if (is_simm32(src)) {
movptr(dst, checked_cast<int32_t>(src));
-------------
PR Review: https://git.openjdk.org/jdk/pull/17343#pullrequestreview-1814156793
More information about the hotspot-dev
mailing list