RFR: 8315545: C1: x86 cmove can use short branches
Aleksey Shipilev
shade at openjdk.org
Mon Sep 4 11:05:47 UTC 2023
On Fri, 1 Sep 2023 14:38:59 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
> Spotted this minor inefficiency when looking at profiling code. C1 profiling code uses `cmove`-s often, and often with immediates, so `LIR_Assembler::cmove` ends up emitting the real jump over the alternative branch. But the alternative branch is just `{reg,stack,const}2reg` conversion, and AFAICS is guaranteed to be short. Therefore, we can use the short branch for that forward jump.
>
> Sample `cmov` disassembly:
>
>
> # Before
> 0.19% 0x00007f1c98cc2d1d: cmp $0x0,%eax
> ╭ 0x00007f1c98cc2d20: jne 0x00007f1c98cc2d2b
> │ 0x00007f1c98cc2d26: mov $0x2,%ecx
> ↘ 0x00007f1c98cc2d2b: and $0x3ffe,%ecx
> 0.54% 0x00007f1c98cc2d31: cmp $0x0,%ecx
>
> # After
> 0.17% 0x00007fcf18dda199: cmp $0x0,%eax
> ╭ 0x00007fcf18dda19c: jne 0x00007fcf18dda1a3
> │ 0x00007fcf18dda19e: mov $0x2,%ecx
> ↘ 0x00007fcf18dda1a3: and $0x3ffe,%ecx
> 1.24% 0x00007fcf18dda1a9: cmp $0x0,%ecx
>
>
> There are some code space savings, visible even on trivial `-Xcomp -XX:TieredStopAtLevel=... HelloWorld`.
>
>
> # Before
> tier1: nmethod total size : 430104 bytes
> tier2: nmethod total size : 467336 bytes
> tier3: nmethod total size : 923368 bytes
>
> # After
> tier1: nmethod total size : 429000 bytes (-0.25%)
> tier2: nmethod total size : 466016 bytes (-0.28%)
> tier3: nmethod total size : 915632 bytes (-0.84%)
>
>
> Additional testing:
> - [x] Linux x86_64 fastdebug `tier1 tier2 tier3`
Testing passes. Reviews are here. Thanks all!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15537#issuecomment-1705068507
More information about the hotspot-compiler-dev
mailing list