[PATCH] D32494: [Loop Deletion] Delete loops that are semantically unreachable

Anna Thomas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 14:45:43 PDT 2017


anna marked 2 inline comments as done.
anna added inline comments.


================
Comment at: lib/Transforms/Scalar/LoopDeletion.cpp:134
+  // of constant conditional branch. We avoid doing this now, because
+  // Loop-SimplifyCFG will be enhanced to change branches in loop from constant
+  // conditional to unconditional, thereby iterating forward across the straight
----------------
anna wrote:
> sanjoy wrote:
> > Why is Loop-SimplifyCFG relevant here?  Won't it only simplify control flow //within// a loop?
> Yes, that's right. The comment maybe confusing. My assumption is that these kind of constant conditional branches are generated by unswitch [1], i.e.  branch is within a loop. At a later point, deleting unreachable loop will be handled by Loop-SimplifyCFG: It will *start* at a constant branch condition, iterating forward through the blocks that will never be executed, and in the process if we reach a loop header which will never be executed, that loop will be deleted.
> 
> So, loop-deletion will just be a subcase of loop-simplifyCFG. At some point, we should just be able to call loop-simplifyCFG in the pass pipeline instead of loop-deletion. 
> 
> [1] If we have constant conditional branches outside of loops generated by some other non-loop passes, we could just use SimplifyCFG to eliminate the code? This brings me to the main reason for the patch: implementing the actual loop deletion, update dom tree etc for unreachable loops, and use that function for Loop-SimplifyCFG.
> 
Actually, with loop-unswitch, the branch can be outside the loop :) So, the merging of loop-simplifyCFG and this version of loop-deletion should fix cases handled by both. 
I'll remove the comment about loop-simplifyCFG. I guess we could have something like this in the pipeline:
```
unswitch
loop-deletion + loop-simplifycfg which handles constant conditional branches (both outside and within loops) that make some loop dead. 
```



https://reviews.llvm.org/D32494





More information about the llvm-commits mailing list