Skip to content
This repository has been archived by the owner. It is now read-only.

8269820: C2 PhaseIdealLoop::do_unroll get wrong opaque node #208

Closed
wants to merge 6 commits into from

Conversation

@huishi-hs
Copy link

@huishi-hs huishi-hs commented Jul 3, 2021

In PhaseIdealLoop::is_canonical_loop_entry check, opaque node can be at either input of compare node, after is_canonical_loop_entry check, opaq node is getting only from compare node's in(2). This might get wrong oqaque node and cause crash/assertion. Detailed crash and analysis is in JBS.

Fix: Adding method PhaseIdealLoop::get_opaque_from_cmp, getting opaque node from cmp node's either input.

Test: Linux X64 tier1/2/3 release/fastdebug no regression.

After this fix, BoolNode::Ideal might remove its code forbidding swapping compare node's input node order when second one is opaque1 node.


Progress

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

Error

 ⚠️ This PR only contains changes already present in the target

Issue

  • JDK-8269820: C2 PhaseIdealLoop::do_unroll get wrong opaque node

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 208

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

Using diff file

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jul 3, 2021

👋 Welcome back hshi! 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 label Jul 3, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jul 3, 2021

@huishi-hs 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.

@mlbridge
Copy link

@mlbridge mlbridge bot commented Jul 3, 2021

Webrevs

@rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Jul 5, 2021

Have you considered preventing split-thru-phi with an opaque input? That would be a better fix IMO.

@huishi-hs
Copy link
Author

@huishi-hs huishi-hs commented Jul 5, 2021

Have you considered preventing split-thru-phi with an opaque input? That would be a better fix IMO.

Thanks for your comment! I'll check other fix and back to you.

@huishi-hs
Copy link
Author

@huishi-hs huishi-hs commented Jul 12, 2021

@rwestrel sorry for late update, I did detail checks about how opaque1 get cloned in loop optimization. Preventing split-thru-phi with an opaque input doesn't work in my investigation.

image
IdealGraph in http://cr.openjdk.java.net/~hshi/8269820/loop_unroll.xml

  1. Opaque1 node is not split in split_thru_phi, it is split when split if in split_up.
  2. Entire split is triggered by Split if on if node 415
  3. Split starts at region node 210 and phi node 213, PhaseIdealLoop::split_up from 213->492->497(recursive to 516)->516->499->458
  4. If disable split 458 in PhaseIdealLoop::split_up, it will crash with other assertions, because "do_split_if" expects "have no instructions in the block containing the IF".

@rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Jul 12, 2021

@huishi-hs Thanks for exploring this fix. I still think blocking split thru phi is the way to go. Otherwise there's a risk that the Opaque1 ends up behind a Phi which would break the pattern entirely. This would require something like this:

rwestrel@e6d6ebe

@huishi-hs
Copy link
Author

@huishi-hs huishi-hs commented Jul 14, 2021

@huishi-hs Thanks for exploring this fix. I still think blocking split thru phi is the way to go. Otherwise there's a risk that the Opaque1 ends up behind a Phi which would break the pattern entirely. This would require something like this:

rwestrel@e6d6ebe

Thanks! Checking if opaque1 node will be splited in split_if looks heavy and this might affect current optimization(might have unexpected degradation). I will do some compile time estimate first.

@huishi-hs huishi-hs force-pushed the opaque_order_wrong branch from a85fba6 to b28b589 Jul 19, 2021
@huishi-hs
Copy link
Author

@huishi-hs huishi-hs commented Jul 19, 2021

@rwestrel
Testing rwestrel@e6d6ebe, testing with -Xcomp -XX:-TieredCompilation (adding elapsedTimer for PhaseIdealLoop::split_if_with_blocks_post and merge_point_safe), 5% - 10% overhead for this extra check in entier split_if_with_blocks_post.

[Total extra check            , 0.0000035 secs]
[Total after can_split_if time, 0.0000646 secs]
[Total extra check            , 0.0000032 secs]
[Total after can_split_if time, 0.0000649 secs]
[Total extra check            , 0.0000023 secs]
[Total after can_split_if time, 0.0000604 secs]
[Total extra check            , 0.0000023 secs]
[Total after can_split_if time, 0.0000214 secs]
[Total extra check            , 0.0000020 secs]
[Total after can_split_if time, 0.0000198 secs]
[Total after can_split_if time, 0.0000010 secs]
[Total extra check            , 0.0000030 secs]
[Total after can_split_if time, 0.0000383 secs]
[Total extra check            , 0.0000026 secs]
[Total after can_split_if time, 0.0000682 secs]

This also disables split if might lost some optimization and might have unexpected degradation. Could you please review new fix? New fix is disabling swapping compare node's input in BoolNode.Ideal, when its second input is phi of opaque1 node.

Before transformation, opaque1 is performed on comve.
image

After transformation, canonical loop limit is constant.
image

@openjdk openjdk bot removed the rfr label Jul 19, 2021
@huishi-hs
Copy link
Author

@huishi-hs huishi-hs commented Jul 19, 2021

Close this as conflict with fix for https://bugs.openjdk.java.net/browse/JDK-8269752

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