RFR: 8365205: C2: Optimize popcount value computation using knownbits [v3]

Jatin Bhateja jbhateja at openjdk.org
Wed Sep 10 12:30:21 UTC 2025


On Tue, 9 Sep 2025 11:46:03 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> test/hotspot/jtreg/compiler/intrinsics/TestPopCountValueTransforms.java line 114:
>> 
>>> 112:         }
>>> 113:         return 1;
>>> 114:     }
>> 
>> Thanks for the tests!
>> 
>> I think it would be quite valuable to have some tests that do not just clamp the range, but also create random `KnownBits`, i.e. with random and/or masks.
>> 
>> For example:
>> `num = (num | ONES) & ZEROS;`
>> 
>> And then you generate `ONES` and `ZEROS` randomly, maybe even using `Generators`?
>> Then round it off with some random range comparisons at the end:
>> `        if (Integer.bitCount(num) >= CON1 && Integer.bitCount(num) <= CON2) {`
>
> Also: how many popcount instructions are left? Should it not at most be 1?

> Thanks for the tests!
> 
> I think it would be quite valuable to have some tests that do not just clamp the range, but also create random `KnownBits`, i.e. with random and/or masks.
> 
> For example: `num = (num | ONES) & ZEROS;`
> 
> And then you generate `ONES` and `ZEROS` randomly, maybe even using `Generators`? Then round it off with some random range comparisons at the end: ` if (Integer.bitCount(num) >= CON1 && Integer.bitCount(num) <= CON2) {`

With Random Ranges, we will not be able to ascertain the count of PopCountI IR node, which is why I created different tests for complete logic sweeping, and the one which retains PopCountIR.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27075#discussion_r2336597616


More information about the hotspot-compiler-dev mailing list