RFR: 8360192: C2: Make the type of count leading/trailing zero nodes more precise [v2]
Qizheng Xing
qxing at openjdk.org
Mon Jun 23 06:03:52 UTC 2025
> The result of count leading/trailing zeros is always non-negative, and the maximum value is integer type's size in bits. In previous versions, when C2 can not know the operand value of a CLZ/CTZ node at compile time, it will generate a full-width integer type for its result. This can significantly affect the efficiency of code in some cases.
>
> This patch makes the type of CLZ/CTZ nodes more precise, to make C2 generate better code. For example, the following implementation runs ~115% faster on x86-64 with this patch:
>
>
> public static int numberOfNibbles(int i) {
> int mag = Integer.SIZE - Integer.numberOfLeadingZeros(i);
> return Math.max((mag + 3) / 4, 1);
> }
>
>
> Testing: tier1, IR test
Qizheng Xing has updated the pull request incrementally with one additional commit since the last revision:
Use `BitsPerX` constant instead of `sizeof`
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/25928/files
- new: https://git.openjdk.org/jdk/pull/25928/files/0faa2099..0d0bb579
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=25928&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=25928&range=00-01
Stats: 4 lines in 1 file changed: 0 ins; 0 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/25928.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/25928/head:pull/25928
PR: https://git.openjdk.org/jdk/pull/25928
More information about the hotspot-compiler-dev
mailing list