[PATCH] D46912: StructurizeCFG: Adjust the loop depth for a subregion to order the nodes correctly

Changpeng Fang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 16:06:17 PDT 2018


cfang created this revision.
cfang added reviewers: nhaehnle, arsenm.
Herald added a subscriber: wdng.

StructurizeCFG::orderNodes basically uses a reverse post-order (RPO) traversal of the region  list to get the order. The only problem with it is that sometimes backedges for outer loops will be visited before backedges for inner loops. To solve this problem, a loop depth based approach has been used to make sure all blocks in this loop has been visited before moving on to outer loop.

However, we found a problem for a SubRegion which is a loop itself:

                            ____

                        |        |
                       V       |
  --> BB1 --> BB2 --> BB3 -->

In this case, BB2 is a SubRegion (loop), and thus its loopdepth is different than that of  BB1 and BB3. This fact will lead BB2 to be placed in the wrong order.

In this work, we treat the SubRegion as a special case and use its exit block to determine the loop and its depth to guard the sorting.


https://reviews.llvm.org/D46912

Files:
  lib/Transforms/Scalar/StructurizeCFG.cpp
  test/CodeGen/AMDGPU/nested-loop-conditions.ll
  test/Transforms/StructurizeCFG/AMDGPU/loop-subregion-misordered.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46912.146949.patch
Type: text/x-patch
Size: 15541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180515/472e68e3/attachment.bin>


More information about the llvm-commits mailing list