Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

8330158: C2: Loop strip mining uses ABS with min int #18813

Closed
wants to merge 2 commits into from

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Apr 17, 2024

This fixes 3 calls to ABS with a min int argument. I think all of them
are harmless:

  • in PhaseIdealLoop::exact_limit(), I removed the call to ABS. The
    check is for a stride of 1 or -1.

  • in OuterStripMinedLoopNode::adjust_strip_mined_loop(), for the
    computation of scaled_iters_long, the stride is passed to ABS()
    and then implicitly casted to long. I now cast the stride to long
    before ABS(). For a min int stride, LoopStripMiningIter * stride
    overflows the int range for all values of LoopStripMiningIter
    except 0 or 1. Those values are handled early on in that method. So
    for a min in stride:

    (jlong)scaled_iters != scaled_iters_long
    

    is always true and the method returns early.

  • in OuterStripMinedLoopNode::adjust_strip_mined_loop(), the
    computation of short_scaled_iters also calls ABS() with the
    stride as argument. But the result of that computation is only used
    if the test for:

    (jlong)scaled_iters != scaled_iters_long
    

    doesn't cause an early return of the method. I reordered statements
    so the ABS() calls happens after that test which will cause an early
    return if the stride is min int.


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-8330158: C2: Loop strip mining uses ABS with min int (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18813

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 17, 2024

👋 Welcome back roland! 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 Apr 17, 2024

@rwestrel This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8330158: C2: Loop strip mining uses ABS with min int

Reviewed-by: shade, kvn, dlong, mbalao

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 126 new commits pushed to the master branch:

  • f1d0e71: 8324577: [REDO] - [IMPROVE] OPEN_MAX is no longer the max limit on macOS >= 10.6 for RLIMIT_NOFILE
  • 74b11cc: 8331004: Serial: Remove unused GenClosure
  • 45ed97f: 8330464: hserr generic events - add entry for the before_exit calls
  • e311ba3: 8330626: ZGC: Windows address space placeholders not managed correctly
  • e923dfe: 8314592: Add shortcut to SymbolLookup::find
  • 1519081: 8330303: Crash: assert(_target_jt == nullptr || _target_jt->vthread() == target_h()) failed
  • 2bb5cf5: 8330155: Serial: Remove TenuredSpace
  • 7bb59dc: 8330670: Obsolete ScavengeBeforeFullGC
  • 174d626: 8328741: serviceability/jvmti/ObjectMonitorUsage/ObjectMonitorUsage.java failed with unexpected owner
  • e681e9b: 8330819: C2 SuperWord: bad dominance after pre-loop limit adjustment with base that has CastLL after pre-loop
  • ... and 116 more: https://git.openjdk.org/jdk/compare/bfff02eef68c80f623419a3f6ceb9fe3121b88f4...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 17, 2024
@openjdk
Copy link

openjdk bot commented Apr 17, 2024

@rwestrel 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 Apr 17, 2024
@mlbridge
Copy link

mlbridge bot commented Apr 17, 2024

Webrevs

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

All right, I agree with this reasoning.

Have you tried running tests with #18751 applied?

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 17, 2024
@rwestrel
Copy link
Contributor Author

Thanks for reviewing this.

Have you tried running tests with #18751 applied?

I only ran the particular test that you mentioned in the bug.

@shipilev
Copy link
Member

I only ran the particular test that you mentioned in the bug.

All right, let me run tests with #18751 applied and see if we have any surprises.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

two comments

int scaled_iters = (int)scaled_iters_long;
int short_scaled_iters = LoopStripMiningIterShortLoop* ABS(stride);
if ((jlong)scaled_iters != scaled_iters_long) {
// Remove outer loop and safepoint (too few iterations)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put more extended comment here. What you have in PR description would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment. Does it look good to you?

remove_outer_loop_and_safepoint(igvn);
return;
}
int short_scaled_iters = LoopStripMiningIterShortLoop * ABS(stride);
Copy link
Contributor

Choose a reason for hiding this comment

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

So stride is not MIN_INT here but the expression still can overflow. Should we use jlong for expression and short_scaled_iters? iter_estimate is jlong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I updated the patch as suggested.

remove_outer_loop_and_safepoint(igvn);
return;
}
int short_scaled_iters = LoopStripMiningIterShortLoop * ABS(stride);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it true that stride can be MIN_INT here, if LoopStripMiningIter == 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a test for LoopStripMiningIter == 1 earlier in the method that causes the method to return.

@dean-long
Copy link
Member

There's also a less obvious use of an abs() idiom in LoopLimitNode::Ideal, when it does

2579      stride_p = -stride_con;

if stride_con is negative. Does it make sense to fix that as part of this PR?

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Looks good.

@shipilev
Copy link
Member

All right, let me run tests with #18751 applied and see if we have any surprises.

I ran Maven CTW, Fuzzer tests, and the rest of OpenJDK jtregs with my ABS-checking patch applied, and there are no surprises. Looks good!

@shipilev
Copy link
Member

@rwestrel, if you could integrate this, we can then go forward with #18751. Thanks!

Copy link
Contributor

@martinuy martinuy left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@rwestrel
Copy link
Contributor Author

@shipilev @dean-long @vnkozlov @martinuy thanks for the reviews

@rwestrel
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Apr 29, 2024

Going to push as commit c615c18.
Since your change was applied there have been 174 commits pushed to the master branch:

  • fb63cba: 8330684: ClassFile API runs into StackOverflowError while parsing certain class' bytes
  • 4e5c25e: 8331108: Unused Math.abs call in java.lang.FdLibm.Expm1#compute
  • 16c7dcd: 8330523: Reduce runtime and improve efficiency of KeepAliveTest
  • c3372c4: 8331134: Port SimpleStringBuilderStrategy to use ClassFile API
  • a078b5e: 8331114: Further improve performance of MethodTypeDesc::descriptorString
  • e3eb652: 8296543: Update exception documentation for ExecutorService.invokeAll overriders as required
  • aa2edd4: 8330686: Fix typos in the DatabaseMetaData javadoc
  • aee91fb: 8296175: Output warning if generated docs contain diagnostic markers
  • a920af2: 8303689: javac -Xlint could/should report on "dangling" doc comments
  • f3bb3e2: 8331153: JFR: Improve logging of jdk/jfr/api/consumer/filestream/TestOrdered.java
  • ... and 164 more: https://git.openjdk.org/jdk/compare/bfff02eef68c80f623419a3f6ceb9fe3121b88f4...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 29, 2024
@openjdk openjdk bot closed this Apr 29, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 29, 2024
@openjdk
Copy link

openjdk bot commented Apr 29, 2024

@rwestrel Pushed as commit c615c18.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants