RFR: 8315554: C1: Replace "cmp reg, 0" with "test reg, reg" on x86
Aleksey Shipilev
shade at openjdk.org
Mon Sep 4 19:06:50 UTC 2023
Noticed this when looking at C1 profiling code. There are plenty of usages for `cmp reg, 0` in C1 x86 code, both in generic `LIR_Assembler::comp_op`, and in some profiling paths.
`test reg, reg` is a denser idiom for this comparison. The difference between `cmp` and `test` on x86 seems to be only with AF (aux carry flag). For ubiquitous int/pointer comparisons, this distinction is irrelevant.
C2 already does this transformation in .ad match rules.
Code size improvements with `-Xcomp -XX:+CITime -XX:TieredStopAtLevel=... Hello`:
# Before
tier1: nmethod total size: 430104 bytes
tier2: nmethod total size: 467336 bytes
tier3: nmethod total size: 923384 bytes
# After
tier1: nmethod total size: 427584 bytes (-0.59%)
tier2: nmethod total size: 464352 bytes (-0.64%)
tier3: nmethod total size: 918328 bytes (-0.55%)
Additional testing:
- [x] Linux x86_64 `tier1 tier2 tier3` x (C1 level 1, 2, 3) x (Parallel, G1, Shenandoah)
-------------
Commit messages:
- Revert incorrect rewrites
- Fix
Changes: https://git.openjdk.org/jdk/pull/15543/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15543&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8315554
Stats: 15 lines in 1 file changed: 5 ins; 0 del; 10 mod
Patch: https://git.openjdk.org/jdk/pull/15543.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/15543/head:pull/15543
PR: https://git.openjdk.org/jdk/pull/15543
More information about the hotspot-compiler-dev
mailing list