RFR: 8360192: C2: Make the type of count leading/trailing zero nodes more precise [v9]
Emanuel Peter
epeter at openjdk.org
Mon Aug 18 14:15:21 UTC 2025
On Fri, 8 Aug 2025 08:21:42 GMT, Qizheng Xing <qxing at openjdk.org> wrote:
>> 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 two additional commits since the last revision:
>
> - Add microbench
> - Add missing test method declarations
I'll run some testing and review afterward.
test/hotspot/jtreg/compiler/c2/gvn/TestCountBitsRange.java line 34:
> 32: * @summary Tests that count bits nodes are handled correctly.
> 33: * @library /test/lib /
> 34: * @requires vm.compiler2.enabled
Is this restriction necessary? IR rules are only run if we have C2 available in debug anyway. Other modes could still profit from correctness checks.
-------------
Changes requested by epeter (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/25928#pullrequestreview-3128565978
PR Review Comment: https://git.openjdk.org/jdk/pull/25928#discussion_r2282534728
More information about the hotspot-compiler-dev
mailing list