[PATCH] D93734: [LoopDeletion] Insert an early exit from dead path in loop

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 20:32:32 PST 2020


reames added a comment.

As implemented, this is a bit too specific to one particular pattern to be commitable, but I think you've got the seed of a good idea here.

I think you can generalize this as follows:

- If all conditions contributing to control flow along the path from header to exit block are loop invariant (use SCEVs definition), then the exit is either taken or not taken equally on all iterations.
- If all exit blocks meet the previous criteria, then the loop must either execute once or be infinite.  If we can prove it's not infinite, it must execute once.
- For a loop which executes exactly once, the backedge is dead.  We can break the backedge, leave the rest of the loop unchanged, and get the result you're looking for.

As a special case of the above (which is probably all we should implement), if all loop exits dominate the backedge, SCEV will be able to compute the backedge taken count as zero.  You can simply check the backedge taken count and break the backedge.

Note that my phrasing doesn't involve reasoning about side effects.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93734/new/

https://reviews.llvm.org/D93734



More information about the llvm-commits mailing list