Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Conversation

@chhagedorn
Copy link
Member

@chhagedorn chhagedorn commented Jul 8, 2021

C2 produces a wrong result for the testcase due to treating a non-reduction AddL node wrongly as a reduction (Node::is_reduction() is true). This node is later part of a pack in the superword algorithm which wrongly treats it as a reduction. As a result, we create an AddReductionVL instead of an AddVL node, letting the test fail.

The wrong reduction can be traced back to AddNode::Ideal where we create a clone of an AddL node which is marked as a reduction. However, the clone itself is no longer a reduction but is still marked as such. Node::clone() simply copies the Flag_is_reduction flag in Node::_flags:

// Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree.
if (add1_op == this_op && !con_right) {
Node *a12 = add1->in(2);
const Type *t12 = phase->type( a12 );
if (t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
!(add1->in(1)->is_Phi() && (add1->in(1)->as_Phi()->is_tripcount(T_INT) || add1->in(1)->as_Phi()->is_tripcount(T_LONG)))) {
assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
add2 = add1->clone();
add2->set_req(2, in(2));
add2 = phase->transform(add2);
set_req_X(1, add2, phase);
set_req_X(2, a12, phase);
progress = this;
add2 = a12;
}
}

I don't think we need to clone the Flag_is_reduction flag by default in Node::clone(). I went through the uses of Node::clone() and I think we only need to clone the flag when copying an entire loop body in PhaseIdealLoop::clone_loop(). That's what I propose as a fix. This approach also avoids the need to think about reductions in future uses of Node::clone() with a special handling for it as it would be required in AddNode::Ideal etc.

I did some performance testing with some common benchmarks which looked good. I also ran the follwing JTreg tests which showed the same number of newly created vectors with and without the fix:

jtreg -testjdk:jdk-18/fastdebug -va -javaoptions:'-server -Xbatch -XX:-TieredCompilation -XX:CICompilerCount=1 -XX:+TraceNewVectors' -J-Djavatest.maxOutputSize=1000000 compiler/c2/cr6340864/ compiler/codegen/ compiler/loopopts/superword/ compiler/vectorization > new_vects.log
grep "new Vector node:" new_vects.log | wc
  20190  521206 4398994

Thanks,
Christian


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8261147: C2: Node is wrongly marked as reduction resulting in a wrong execution due to wrong vector instructions

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk17 pull/231/head:pull/231
$ git checkout pull/231

Update a local copy of the PR:
$ git checkout pull/231
$ git pull https://git.openjdk.java.net/jdk17 pull/231/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 231

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk17/pull/231.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 8, 2021

👋 Welcome back chagedorn! 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 openjdk bot added the rfr Pull request is ready for review label Jul 8, 2021
@openjdk
Copy link

openjdk bot commented Jul 8, 2021

@chhagedorn 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.java.net label Jul 8, 2021
@mlbridge
Copy link

mlbridge bot commented Jul 8, 2021

Webrevs

Copy link
Member

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

@openjdk
Copy link

openjdk bot commented Jul 8, 2021

@chhagedorn 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:

8261147: C2: Node is wrongly marked as reduction resulting in a wrong execution due to wrong vector instructions

Reviewed-by: thartmann, kvn

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 24 new commits pushed to the master branch:

  • 9e75f92: 8269738: AssertionError when combining pattern matching and function closure
  • 168af2e: 8269828: corrections in some instruction patterns for KNL x86 platform
  • fa08cc6: 8268766: Desugaring of pattern matching enum switch should be improved
  • 4f70759: 8270006: Switches with 'case null:' should be exhaustive
  • 8f798b8: 8269746: C2: assert(!in->is_CFG()) failed: CFG Node with no controlling input?
  • c812bbb: 8269929: (test) Add diagnostic info to ProceessBuilder/Basic.java for unexpected output
  • 6000950: 8269185: Directories in /opt/runtimepackagetest and /path/to/jdk-17 are different
  • 1f2bf1d: 8269879: [PPC64] C2: Math.rint intrinsic uses wrong rounding mode
  • 7fcd5ca: 8266036: class file for sun.misc.Contended not found
  • a49b1dc: 8269772: [macos-aarch64] test compilation failed with "SocketException: No buffer space available"
  • ... and 14 more: https://git.openjdk.java.net/jdk17/compare/e14801cdd9b108aa4ca47d0bc1dc67fca575764c...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 ready Pull request is ready to be integrated label Jul 8, 2021
@chhagedorn
Copy link
Member Author

Thanks Tobias for your review!

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.

Good.

@chhagedorn
Copy link
Member Author

Thanks Vladimir for your review!

@chhagedorn
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 9, 2021

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

  • 1196b35: 8270151: IncompatibleClassChangeError on empty pattern switch statement case
  • 885f7b1: 8269146: Missing unreported constraints on pattern and other case label combination
  • 62ff55d: 8269952: compiler/vectorapi/VectorCastShape*Test.java tests failed on avx2 machines
  • 46c610c: 8269840: Update Platform.isDefaultCDSArchiveSupported() to return true for aarch64 platforms
  • 6401633: 8269722: NPE in HtmlDocletWriter
  • 9acb2a6: 8270109: ProblemList 4 SA tests on macOS-aarch64
  • f46a917: 6766844: ByteArrayInputStream#read with a byte array of length 0 not consistent with InputStream when at EOF
  • 9e75f92: 8269738: AssertionError when combining pattern matching and function closure
  • 168af2e: 8269828: corrections in some instruction patterns for KNL x86 platform
  • fa08cc6: 8268766: Desugaring of pattern matching enum switch should be improved
  • ... and 21 more: https://git.openjdk.java.net/jdk17/compare/e14801cdd9b108aa4ca47d0bc1dc67fca575764c...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Jul 9, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 9, 2021
@openjdk
Copy link

openjdk bot commented Jul 9, 2021

@chhagedorn Pushed as commit f791fdf.

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

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

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.java.net integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants