[PATCH] D35411: [SimplifyCFG] Defer folding unconditional branches to LateSimplifyCFG if it can destroy canonical loop structure.

Chad Rosier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 08:37:32 PDT 2017


mcrosier added a comment.

Let me see if I can describe the problem and your approach to fixing the issue in my own words.

Currently, JumpThreading and SimplifyCFG avoid threading/merging "empty" loop headers as this would break the canonical form of the loop; the CFG edge being optimized is between the loop header and it's successor.  Your approach is to also avoid merging the incoming edges (i.e., back edges) of the loop as well to avoid breaking the canonical form of the loop.  Then later in late-SimplifyCFG and CodeGen prepare you more aggressively remove these empty blocks.

Sound about right?



================
Comment at: lib/Transforms/Scalar/JumpThreading.cpp:239
           BB != &BB->getParent()->getEntryBlock() &&
           // If the terminator is the only non-phi instruction, try to nuke it.
+          BB->getFirstNonPHIOrDbg()->isTerminator() && !LoopHeaders.count(BB) &&
----------------
This comment needs some additional explaining after your change.

You're avoiding the case where we're skipping an empty block whose successor is a loop header, which IIUC when merged destroys the canonical form of the loop.  You're then relying on CodeGenPrepare to eliminate these empty blocks.


https://reviews.llvm.org/D35411





More information about the llvm-commits mailing list