RFR: 8365205: C2: Optimize popcount value computation using knownbits [v9]
Emanuel Peter
epeter at openjdk.org
Fri Sep 19 09:41:04 UTC 2025
On Fri, 19 Sep 2025 09:25:56 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> Jatin Bhateja has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Review comments resolutions
>
> test/hotspot/jtreg/compiler/intrinsics/TestPopCountValueTransforms.java line 54:
>
>> 52: static final long rand_bndL2 = G.longs().next();
>> 53: static final long rand_popcL1 = G.uniformLongs(0, 32).next();
>> 54: static final long rand_popcL2 = G.uniformLongs(0, 32).next();
>
> Why did you limit the range for longs to 32? Can it not go up to 64?
> I asked for an explanation (in a code comment) of those that you restrict here, which you have not done, and just "resolved" it instead:
> https://github.com/openjdk/jdk/pull/27075#discussion_r2351166568
If you do restrict it, then at least go over the range a little bit. Why?
You check `Integer.bitCount(num) < rand_popcI2`. The max value you get here is 32, so we could never get a constant folding case for the range `0..32`. Maybe that is ok, but we potentially miss a chance to find something we did not even anticipate.
That is why I would recommend **not** to constrain the values, unless you really have a good reason and write it down in a code comment.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27075#discussion_r2362316509
More information about the hotspot-compiler-dev
mailing list