[PATCH] D132199: [LoopPassManager] Ensure to construct loop nests with the outermost loop

Congzhe Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 21:02:18 PDT 2022


congzhe created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
congzhe requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch is to resolve the bug reported and discussed in https://reviews.llvm.org/D124926#3718761, https://reviews.llvm.org/D124926#3719876.

The bug is that when we run loop interchange twice with the new pass manager using `-passes="loop(loop-interchange,loop-interchange)"` on the IR attached in https://reviews.llvm.org/D124926#3718761, it hangs forever and consumes more and more memory. The IR is added as a new lit test file in this patch.

The underlying reason, as described in https://reviews.llvm.org/D124926#3719876, is that loop interchange is a loopnest pass under the new pass manager, but the loop nest is not constructed correctly by the loop pass manager after completing the first loop interchange pass. The loop in the IR is a triply nested loop. But after completing the first interchange pass, the loop nest constructed is a doubly nested loop which is incorrect and caused the trouble.

The reason that the loop nest is constructed incorrectly is that the outermost loop `L` has changed after the first interchange, and what was the original outermost loop is not the current outermost loop anymore. The original outermost loop `L` has actually become the middle loop. However the loop nest is still constructed based on `L`, that is why the loop nest is constructed as a doubly nested loop.

What this patch does is that, in the loop pass manager before running each pass, we always let `L` point to the current outermost loop, because loop nests should be constructed based on the outermost loop and it is only valid to run a loopnest pass when `L` is the outermost loop.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132199

Files:
  llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
  llvm/lib/Transforms/Scalar/LoopPassManager.cpp
  llvm/test/Transforms/LoopInterchange/interchanged-loop-nest-4.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132199.453868.patch
Type: text/x-patch
Size: 7173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220819/9f954bb3/attachment.bin>


More information about the llvm-commits mailing list