RFR: 8315545: C1: x86 cmove can use short branches
Aleksey Shipilev
shade at openjdk.org
Fri Sep 1 15:19:57 UTC 2023
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:
- [ ] Linux x86_64 fastdebug `tier1 tier2 tier3`
-------------
Commit messages:
- Fix
Changes: https://git.openjdk.org/jdk/pull/15537/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15537&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8315545
Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/15537.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/15537/head:pull/15537
PR: https://git.openjdk.org/jdk/pull/15537
More information about the hotspot-compiler-dev
mailing list