RFR: 8323503: x86: Shorter movptr(reg, imm) for 32-bit unsigned immediates [v3]

Thomas Stuefe stuefe at openjdk.org
Fri Jan 12 17:37:20 UTC 2024


On Thu, 11 Jan 2024 09:17:35 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%)
>
> Aleksey Shipilev has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Revert "Just do checked_cast<int32_t>"
>   
>   This reverts commit 3f94218b46b6b0492ffcc24404b7bb5546b3318a.

Tests on my issue are green with your variant of movptr

-------------

PR Comment: https://git.openjdk.org/jdk/pull/17343#issuecomment-1889698975


More information about the hotspot-dev mailing list