Integrated: 8360192: C2: Make the type of count leading/trailing zero nodes more precise

Qizheng Xing qxing at openjdk.org
Mon Dec 8 13:20:20 UTC 2025


On Mon, 23 Jun 2025 03:31:36 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

This pull request has now been integrated.

Changeset: b83bf071
Author:    Qizheng Xing <qxing at openjdk.org>
Committer: Emanuel Peter <epeter at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/b83bf0717eb8926efcf85a32be08f33a41bb48dd
Stats:     801 lines in 4 files changed: 735 ins; 54 del; 12 mod

8360192: C2: Make the type of count leading/trailing zero nodes more precise

Reviewed-by: qamai, epeter, jbhateja

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

PR: https://git.openjdk.org/jdk/pull/25928


More information about the hotspot-compiler-dev mailing list