RFR: 8364766: C2: Improve Value() of DivI and DivL for non-constant inputs [v6]

Benoît Maillard bmaillard at openjdk.org
Mon Aug 25 09:16:54 UTC 2025


On Sat, 23 Aug 2025 09:05:10 GMT, Tobias Hotz <duke at openjdk.org> wrote:

>> This PR improves the value of interger division nodes.
>> Currently, we only emit a good type if either input is constant. But we can also cover the generic case. It does that by finding the four corners of the division. This is guranteed to find the extrema that we can use for min/max. Some special logic is required for MIN_INT / -1, though, as this is a special case
>> We also need some special logic to handle ranges that cross zero, but in this case, we just need to check for the negative and positive range once.
>> This also cleans up and unifies the code paths for DivINode and DivLNode.
>> I've added some tests to validate the optimization. Without the changes, some of these tests fail.
>
> Tobias Hotz has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Remove too strict assert from old code path

Thanks for working on this change, I think this an important optimization opportunity that was previously missing. The code is very clear. I only have one nit.

src/hotspot/share/opto/divnode.cpp line 543:

> 541:   NativeType i2_hi = i2->_hi == 0 ? -1 : i2->_hi;
> 542:   NativeType min_val = std::numeric_limits<NativeType>::min();
> 543:   assert(min_val == min_jint || min_val == min_jlong, "min has to be either min_jint or min_jlong");

I find this assert a little confusing, as its outcome is completely independent from the inputs of the function. I would remove it

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

Marked as reviewed by bmaillard (Author).

PR Review: https://git.openjdk.org/jdk/pull/26143#pullrequestreview-3150548871
PR Review Comment: https://git.openjdk.org/jdk/pull/26143#discussion_r2297542349


More information about the hotspot-compiler-dev mailing list