RFR: 8315554: C1: Replace "cmp reg, 0" with "test reg, reg" on x86

Aleksey Shipilev shade at openjdk.org
Wed Sep 6 15:37:40 UTC 2023


On Fri, 1 Sep 2023 17:28:03 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> 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)

All right then!

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

PR Comment: https://git.openjdk.org/jdk/pull/15543#issuecomment-1708623881


More information about the hotspot-compiler-dev mailing list