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

Tobias Hotz duke at openjdk.org
Sat Oct 25 13:43:06 UTC 2025


On Sun, 19 Oct 2025 19:20:58 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 two additional commits since the last revision:
> 
>  - Add additional nodes to fail conditions to detect idealized/transformed DivI Nodes that did not constant fold
>  - Remove checks for bottom and reorganize DivI/DivL Value functions

Yeah this sucks, as it stands I do not have enough info to debug this...
I noticed that the new types looks wrong if I read the input nodes correctly. It should be min_long / -2, but it is min_long / -1024. I can however not reproduce this locally:
<img width="847" height="486" alt="grafik" src="https://github.com/user-attachments/assets/cbbdeeaa-94bb-4e39-a808-d657e65c3a02" />
I have the same input nodes in this example, but the correct type for the div node here.
I've starred at the code now for a bit and I am still not sure what could have caused this. And I am afraid I can't debug without the test case...

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

PR Comment: https://git.openjdk.org/jdk/pull/26143#issuecomment-3446716303


More information about the hotspot-compiler-dev mailing list