RFR: 8360192: C2: Make the type of count leading/trailing zero nodes more precise [v18]
duke
duke at openjdk.org
Sat Dec 6 09:46:14 UTC 2025
On Fri, 5 Dec 2025 08:57:06 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 with a new target base due to a merge or a rebase. The pull request now contains 24 commits:
>
> - Merge branch 'master' into enhance-clz-type
> - Make code more compact
> - Fix include order
> - Merge branch 'master' into enhance-clz-type
> - Merge branch 'master' into enhance-clz-type
> - Fix constant fold
> - Remove redundant import
> - Add random range tests
> - Add more comments to IR test
> - Add more constant folding tests for CLZ/CTZ
> - ... and 14 more: https://git.openjdk.org/jdk/compare/674cc3ee...f0687754
@MaxXSoft
Your change (at version f0687754fca4ce08f650bb49c6e96ebb0d5b99bf) is now ready to be sponsored by a Committer.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25928#issuecomment-3619817305
More information about the hotspot-compiler-dev
mailing list