Skip to content

Commit

Permalink
[GR-52225] Backport to 23.1: Loop fragment: ensure we are not killing…
Browse files Browse the repository at this point in the history
… control flow when we have nodes in head position not in counted position.

PullRequest: graal/17062
  • Loading branch information
medoussboug committed Feb 26, 2024
2 parents b5f86be + 3a18dd7 commit fc87f2d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ protected CompareNode placeNewSegmentAndCleanup(LoopEx loop, EconomicMap<Node, N
usage.replaceFirstInput(trueSuccessor, loopTest.trueSuccessor());
}

graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "After stitching new segment into control flow after existing one");

assert graph.isBeforeStage(StageFlag.VALUE_PROXY_REMOVAL) || mainLoopBegin.loopExits().count() <= 1 : "Can only merge early loop exits if graph has value proxies " +
mainLoopBegin;

Expand All @@ -296,7 +298,16 @@ protected CompareNode placeNewSegmentAndCleanup(LoopEx loop, EconomicMap<Node, N
graph.removeSplitPropagate(newSegmentLoopTest, loopTest.trueSuccessor() == mainCounted.getBody() ? trueSuccessor : falseSuccessor);

graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "Before placing segment");
if (mainCounted.getBody().next() instanceof LoopEndNode) {
if (mainCounted.getBody().next() instanceof LoopEndNode && mainCounted.getLimitTest().predecessor() == mainCounted.loop.loopBegin()) {
/**
* We assume here that the body of the loop is completely empty, i.e., we assume
* that there is no control flow in the counted loop body. This however means that
* we also did not have any code between the loop header and the counted begin (we
* allow a few special nodes there). Else we would be killing nodes that are as well
* between - that potentially could be used by loop phis (which we also disallow).
* Thus, just be safe here and ensure we really see the pattern we are expect namely
* a completely empty (fixed nodes) loop body.
*/
GraphUtil.killCFG(getDuplicatedNode(mainLoopBegin));
} else {
AbstractBeginNode newSegmentBegin = getDuplicatedNode(mainLoopBegin);
Expand Down

0 comments on commit fc87f2d

Please sign in to comment.