[PATCH] D33001: [RuntimeUnrolling] Add logic for loops with multiple exit blocks

Anna Thomas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 09:04:48 PDT 2017


anna added inline comments.


================
Comment at: lib/Transforms/Utils/LoopUnrollRuntime.cpp:294
+static void
+CloneLoopBlocks(Loop *L, Value *NewIter, const bool CreateRemainderLoop,
+                const bool UseEpilogRemainder, BasicBlock *InsertTop,
----------------
anna wrote:
> reames wrote:
> > Orthogonal to your change, but this code would be much simpler if we always created the remainder loop and then broke the backedge (removing the loop) if we knew the inserted loop was trivial.
> Actually, I'm not convinced if the code would be simpler.
> So, there are multiple data structures updated when this "new" remainder loop gets generated, apart from the updates to the CFG edges.
> After `CloneLoopBlocks`, we'll need to call a modified version of `deleteDeadLoop` (which is currently in LoopDeletion pass). So, apart from breaking the backedge, we'll need to update the LPM to state that the (remainder) loop we just added should be deleted. 
I realized one more thing while working on a different problem in loop deletion: the LPM Updater *cannot* remove this remainder loop. The removal works only for current loop and subloops within it. This remainder loop is not a subloop. 

And just breaking the backedge without deleting the loop, will break the loop structure and leave the loop in the LPM, which is incorrect. 

This makes the `CreateRemainderLoop` checks pretty useful! 

We can still generate the remainder loop code unconditionally and rely on some later pass on simplifyCFG to remove this loop (if it handles this optimization of single trip count 'loop'). 


https://reviews.llvm.org/D33001





More information about the llvm-commits mailing list