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

Christian Hagedorn chagedorn at openjdk.org
Thu Nov 13 12:53:33 UTC 2025


On Sun, 9 Nov 2025 09:34:52 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:
> 
>   Move Test to compiler.igvn

test/hotspot/jtreg/compiler/igvn/IntegerDivValueTests.java line 77:

> 75: 
> 76:     @Test
> 77:     @IR(failOn = {IRNode.DIV_I, IRNode.DIV_L, IRNode.URSHIFT_I, IRNode.URSHIFT_L, IRNode.RSHIFT_I, IRNode.RSHIFT_L, IRNode.MUL_I, IRNode.MUL_L, IRNode.ADD_I, IRNode.ADD_L, IRNode.SUB_I, IRNode.SUB_L, IRNode.AND_I, IRNode.AND_L})

Drive-by comment: Since you only care about the absence of these nodes, you can also use the generic `DIV`, `MUL`, `URSHIFT` etc. `IRNode` definitions (should exist for all your cases) to make it easier to read.

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

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


More information about the hotspot-compiler-dev mailing list