Skip to content

8356813: Improve Mod(I|L)Node::Value #25254

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

SirYwell
Copy link
Member

@SirYwell SirYwell commented May 15, 2025

This change improves the precision of the Mod(I|L)Node::Value() functions.

I reordered the structure a bit. First, we handle constants, afterwards, we handle ranges. The bottom checks seem to be excessive (Type::BOTTOM is covered by using isa_(int|long)(), the local bottom is just the full range). Given we can even give reasonable bounds if only one input has any bounds, we don't want to return early.
The changes after that are commented. Please let me know if the explanations are good, or if you have any suggestions.

Monotonicity

Before, a 0 divisor resulted in Type(Int|Long)::POS. Initially I wanted to keep it this way, but that violates monotonicity during PhaseCCP. As an example, if we see a 0 divisor first and a 3 afterwards, we might try to go from >=0 to -2..2, but the meet of these would be >=-2 rather than -2..2. Using Type(Int|Long)::ZERO instead (zero is always in the resulting value if we cover a range).

Testing

I added tests for cases around the relevant bounds. I also ran tier1, tier2, and tier3 but didn't see any related failures after addressing the monotonicity problem described above (I'm having a few unrelated failures on my system currently, so separate testing would be appreciated in case I missed something).

Please review and let me know what you think.

Other

The UMod(I|L)Nodes were adjusted to be more in line with its signed variants. This change diverges them again, but similar improvements could be made after #17508.

During experimenting with these changes, I stumbled upon a few things that aren't directly related to this change, but might be worth to further look into:

  • If the divisor is a constant, we will directly replace the Mod(I|L)Node with more but less expensive nodes in ::Ideal(). Type analysis for these nodes combined is less precise, means we miss potential cases were this would help e.g., removing range checks. Would it make sense to delay the replacement?
  • To force non-negative ranges, I'm using char. I noticed that method parameters of sub-int integer types all fall back to TypeInt::INT. This seems to be an intentional change of 200784d. The bug report is private, so I can't really judge if that part is necessary, but it seems odd.

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8356813: Improve Mod(I|L)Node::Value (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25254/head:pull/25254
$ git checkout pull/25254

Update a local copy of the PR:
$ git checkout pull/25254
$ git pull https://git.openjdk.org/jdk.git pull/25254/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25254

View PR using the GUI difftool:
$ git pr show -t 25254

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25254.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 15, 2025

👋 Welcome back hgreule! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented May 15, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title 8356813 8356813: Improve Mod(I|L)Node::Value May 15, 2025
@openjdk
Copy link

openjdk bot commented May 15, 2025

@SirYwell The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label May 15, 2025
@SirYwell SirYwell marked this pull request as ready for review May 15, 2025 16:51
@openjdk openjdk bot added the rfr Pull request is ready for review label May 15, 2025
@mlbridge
Copy link

mlbridge bot commented May 15, 2025

Webrevs

@merykitty
Copy link
Member

Using Type(Int|Long)::ZERO instead (zero is always in the resulting value if we cover a range).

Can we return Type::TOP instead?

Besides, #17508 should be merged right after JDK-25 folk, do you want to wait for it first?

@SirYwell
Copy link
Member Author

Using Type(Int|Long)::ZERO instead (zero is always in the resulting value if we cover a range).

Can we return Type::TOP instead?

That should work too and might be more intuitive. I assume there also isn't much benefit in constant-folding users of the mod if the mod is known to fail (which seems to be the only benefit of not returning TOP?).

Besides, #17508 should be merged right after JDK-25 folk, do you want to wait for it first?

We can wait if it makes sense to do the unsigned variants here too, but I'm also fine with doing it separately.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants