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

Tobias Hotz duke at openjdk.org
Sun Oct 19 10:24:13 UTC 2025


On Mon, 25 Aug 2025 09:19:24 GMT, Manuel Hässig <mhaessig at openjdk.org> wrote:

>> 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
>
> It depends on the template type. I would rather keep it to sanity check that the minimum value of `NativeType` is as we expect. If that does not hold, the optimization below is potentially wrong and has UB.

As @mhaessig said, this is a simple sanity check and helps establishing a mental model of what min is (IMO).
I've turned it into a static_assert. If we need more types later on, I can expand it.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26143#discussion_r2443238389


More information about the hotspot-compiler-dev mailing list