RFR: 8356813: Improve Mod(I|L)Node::Value [v2]

Hannes Greule hgreule at openjdk.org
Fri May 30 07:26:14 UTC 2025


On Wed, 28 May 2025 09:47:59 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Hannes Greule has updated the pull request incrementally with three additional commits since the last revision:
>> 
>>  - Update ModL comment
>>  - Use TOP instead of ZERO
>>  - Apply suggested test changes
>
> test/hotspot/jtreg/compiler/c2/gvn/ModINodeValueTests.java line 201:
> 
>> 199:         // in bounds, cannot optimize
>> 200:         return ((byte) x) % (((char) y) + 1) <= -128;
>> 201:     }
> 
> Nice work with the examples you already have, and randomizing some of it!
> 
> I would like to see one more generalized test.
> - compute `res = lhs % rhs`
> - Truncate both `lhs` and `rhs` with randomly produced bounds from Generators, like this: `lhs = Math.max(lo, Math.min(hi, lhs))`.
> - Below, add all sorts of comparisons with random constants, like this: `if (res < CON) { sum += 1; }`. If the output range is wrong, this could wrongly constant fold, and allow us to catch that.
> 
> Then fuzz the generated method a few times with random inputs for `lhs` and `rhs`, and check that the `sum` and `res` value are the same for compiled and interpreted code.
> 
> I hope that makes sense :)
> This is currently my best method to check if ranges are correct, and I think it is quite important because often tests are only written with constants in mind, but less so with ranges, and then we mess up the ranges because it is just too tricky.
> 
> This is an example, where I asked someone to try this out as well:
> https://github.com/openjdk/jdk/pull/23089/files#diff-12bebea175a260a6ab62c22a3681ccae0c3d9027900d2fdbd8c5e856ae7d1123R404-R422

I introduced tests now very similar to the example you linked. I added a `@ForceInline` annotation to the `clamp` method to avoid test failures there. I ran the tests with REPEAT_COUNT=200 and didn't encounter any failure.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25254#discussion_r2115297961


More information about the hotspot-compiler-dev mailing list