RFR: 8323503: x86: Shorter movptr(reg, imm) for 32-bit unsigned immediates
Aleksey Shipilev
shade at openjdk.org
Wed Jan 10 18:57:34 UTC 2024
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%)
-------------
Commit messages:
- Fix
Changes: https://git.openjdk.org/jdk/pull/17343/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17343&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8323503
Stats: 4 lines in 2 files changed: 3 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/17343.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/17343/head:pull/17343
PR: https://git.openjdk.org/jdk/pull/17343
More information about the hotspot-dev
mailing list