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

8325746: Refactor Loop Unswitching code #17842

Closed
wants to merge 14 commits into from
16 changes: 8 additions & 8 deletions src/hotspot/share/opto/loopUnswitch.cpp
Original file line number Diff line number Diff line change
@@ -36,11 +36,11 @@
// Loop Unswitching is a loop optimization to move an invariant, non-loop-exiting test in the loop body before the loop.
// Such a test is either always true or always false in all loop iterations and could therefore only be executed once.
// To achieve that, we duplicate the loop and change the original and cloned loop as follows:
// - Original loop -> true-path-loop: The true-path-block of the invariant, non-loop-exiting test in the original loop
// is kept while the false-path-block is killed. We call this unswitched loop version
// - Original loop -> true-path-loop: The true-path-path of the invariant, non-loop-exiting test in the original loop
// is kept while the false-path-path is killed. We call this unswitched loop version
// the true-path-loop.
// - Cloned loop -> False-path-loop: The false-path-block of the invariant, non-loop-exiting test in the cloned loop
// is kept while the true-path-block is killed. We call this unswitched loop version
// - Cloned loop -> False-path-loop: The false-path-path of the invariant, non-loop-exiting test in the cloned loop
// is kept while the true-path-path is killed. We call this unswitched loop version
// the false-path loop.
//
// The invariant, non-loop-exiting test can now be moved before both loops (to only execute it once) and turned into a
@@ -60,12 +60,12 @@
// Original Loop true? false?
// stmt1 / \
// if (invariant-test) UNSWITCHED [Cloned Parse Predicates] [Cloned Parse Predicates]
// if-block =========> [Cloned Template [Cloned Template
// if-path =========> [Cloned Template [Cloned Template
// else Assertion Predicates] Assertion Predicates]
// // could be empty | |
// [else-block] True-Path-Loop False-Path-Loop
// [else-path] True-Path-Loop False-Path-Loop
// stmt2 cloned stmt1 cloned stmt1
// Endloop cloned if-block [cloned else-block]
// Endloop cloned if-path [cloned else-path]
// cloned stmt2 cloned stmt2
// Endloop Endloop
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be the other way around: the if-path is empty and the else-path has code? Or are you just trying to suggest that there could be an empty path, and that this would really simplify one of the cloned loops now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it would be a simplification. But as suggested in the other comment. It might create more confusion than actually helping.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put resulting unstitched graph on separate following lines? Comment line are too long.


@@ -245,7 +245,7 @@ class OriginalLoop : public StackObj {
#endif // ASSERT

// Remove the unswitch candidate If nodes in both unswitched loop versions which are now dominated by the loop selector
// If node. Keep the true-path-block in the true-path-loop and the false-path-block in the false-path-loop by setting
// If node. Keep the true-path-path in the true-path-loop and the false-path-path in the false-path-loop by setting
// the bool input accordingly. The unswitch candidate If nodes are folded in the next IGVN round.
void remove_unswitch_candidate_from_loops(const UnswitchedLoopSelector& unswitched_loop_selector) {
IfNode* unswitching_candidate = unswitched_loop_selector.unswitch_candidate();