Skip to content

Commit

Permalink
loop fragment: ensure we are not killing control flow when we have
Browse files Browse the repository at this point in the history
nodes in head/tail counted position that are actually empty themselves
(skipable)
  • Loading branch information
davleopo committed Feb 19, 2024
1 parent c1bc909 commit 89ce6d1
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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(GraphState.StageFlag.VALUE_PROXY_REMOVAL) || mainLoopBegin.loopExits().count() <= 1 : "Can only merge early loop exits if graph has value proxies " +
mainLoopBegin;

Expand All @@ -300,7 +302,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 89ce6d1

Please sign in to comment.