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

Tobias Hotz duke at openjdk.org
Wed Oct 29 20:23:10 UTC 2025


> 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 with a new target base due to a merge or a rebase. The pull request now contains 25 commits:

 - Add new asserts and change special case calculations
 - Merge branch 'master' of https://github.com/openjdk/jdk into better_interger_div_type
 - 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
 - Adjust long constant folding test as well
 - Adjust test, assert and comments
 - Remove too strict assert from old code path
 - Fix if condition
 - Simplify the special case path
 - Add a simple path for non-special-case corner calculation
 - ... and 15 more: https://git.openjdk.org/jdk/compare/32697bf6...45a91bd0

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

Changes: https://git.openjdk.org/jdk/pull/26143/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=26143&range=08
  Stats: 713 lines in 2 files changed: 609 ins; 90 del; 14 mod
  Patch: https://git.openjdk.org/jdk/pull/26143.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26143/head:pull/26143

PR: https://git.openjdk.org/jdk/pull/26143


More information about the hotspot-compiler-dev mailing list