[PATCH] D94378: [LoopDeletion] Handle inner loops w/untaken backedges

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 10 17:08:29 PST 2021


reames created this revision.
reames added reviewers: fhahn, jdoerfert, jonpa, atmnpatel.
Herald added subscribers: dantrushin, bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

This builds on the restricted after initial revert form of D93906 <https://reviews.llvm.org/D93906>, and adds back support for breaking backedges of inner loops.  It turns out the original invalidation logic wasn't quite right, specifically around the handling of LCSSA.

When breaking the backedge of an inner loop, we can cause blocks which were in the outer loop only because they were also included in a sub-loop to be removed from both loops.  This results in the exit block set for our original parent loop changing, and thus a need for new LCSSA phi nodes.

This case happens when the inner loop has an exit block which is also an exit block of the parent, and there's a block in the child which reaches an exit to said block without also reaching an exit to the parent loop.

(I'm describing this in terms of the immediate parent, but the problem is general for any transitive parent in the nest.)

At a high level, we seem to have two choices.  Either a) rebuild lcssa if needed, or b) restrict the transformation such that an lcssa rebuild isn't needed.

The lcssa rebuild approach is potentially expensive in the worst case.  Each rebuild is potentially O(N^2) in the number of instructions in the loop being rebuilt.  At worst, we could have N sub-loops (since each must contain at least one instruction), resulting in a worst case example of a whole forest of loops w/zero btc resulting in O(N^3).  We have lots of precedent for this being an acceptable expense, but I want to explicit raise the issue for review.  Thoughts?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94378

Files:
  llvm/lib/Transforms/Scalar/LoopDeletion.cpp
  llvm/lib/Transforms/Utils/LoopUtils.cpp
  llvm/test/Transforms/IndVarSimplify/X86/pr45360.ll
  llvm/test/Transforms/LoopDeletion/zero-btc.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94378.315681.patch
Type: text/x-patch
Size: 5046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210111/9617168c/attachment.bin>


More information about the llvm-commits mailing list