Skip to content

Conversation

@dafedafe
Copy link
Contributor

@dafedafe dafedafe commented Dec 19, 2025

Issue

Olivier's fuzzer found a test that makes C2 crash while running the optimization that collapses the addition with overflow-protection (fold_subI_no_underflow_pattern).

Causes

The crash happens because during fold_subI_no_underflow_pattern the first input of the AddL node (see comment below) becomes top.

// x con2
// | |
// AddL clamp2
// | |
// Max/MinL con1
// | |
// AddL clamp1
// | |
// Max/MinL (n)

This happens because of a whole IfFalse subgraph that dies and nodes are being removed. AddL is not removed immediately as it has another input which is still alive but it is put in the IGVN worklist instead.

image

Unfortunately the fold_subI_no_underflow_pattern optimization runs before the next GVN pass and triggers the assert.

Fix

fold_subI_no_underflow_pattern should actually take into account that we could have the graph in such a state and that x could be top. So, the sensible fix is not to presume x to be of type long and bailout if it is not.

Testing

Tier 1-3+
(also checked for new regression test failure before the change)


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-8373525: C2: assert(_base == Long) failed: Not a Long (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28920

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 19, 2025

👋 Welcome back dfenacci! 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 Dec 19, 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 JDK-8373525: C2: assert(_base == Long) failed: Not a Long 8373525: C2: assert(_base == Long) failed: Not a Long Dec 19, 2025
@openjdk
Copy link

openjdk bot commented Dec 19, 2025

@dafedafe 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.

@dafedafe dafedafe marked this pull request as ready for review December 19, 2025 14:02
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 19, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 19, 2025

Webrevs

Copy link
Contributor

@mhaessig mhaessig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this, @dafedafe. The fix looks good. I only have some minor comments on the test.

Copy link
Contributor

@mhaessig mhaessig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my comments. Looks good to me.

Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, looks good to me, too, thanks!

const TypeLong* x_long = phase->type(x)->isa_long();
// Collapsed graph not equivalent if potential over/underflow -> bailing out (*)
if (can_overflow(phase->type(x)->is_long(), con1->get_long() + con2->get_long())) {
if (x_long == nullptr || can_overflow(x_long, con1->get_long() + con2->get_long())) {
Copy link
Member

@chhagedorn chhagedorn Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to to add a comment about when x_long is not a long as described in the PR description.

* @summary Test for the check of a valid type (long) for the input variable of overflow protection
* @run main/othervm -Xbatch -XX:-TieredCompilation -XX:CompileCommand=compileonly,compiler.loopopts.TestValidTypeInOverflowProtection::test
* ${test.main.class}
* @run driver ${test.main.class}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be main to allow to pass flags in.

Suggested change
* @run driver ${test.main.class}
* @run main ${test.main.class}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler [email protected] rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

3 participants