[PATCH] D123231: [StructurizeCFG] Improve basic block ordering

Ruiling, Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 27 18:35:04 PDT 2022


ruiling added a comment.

In D123231#3613586 <https://reviews.llvm.org/D123231#3613586>, @bcahoon wrote:

> In D123231#3611240 <https://reviews.llvm.org/D123231#3611240>, @ruiling wrote:
>
>> The issue @critson reported in the related change reminds to take a careful look of this change. I think there is one critical correctness issue need to be fixed. When we are moving the exit block into the loop, **we need to make sure there is no convergent operation in the exit block**, otherwise we may change the threads that will participate the convergent operation if the threads exit the loop non-uniformly. So we have to scan all the instructions in the exit block before making the reorder decision.
>
> Hi @ruiling can you expand upon this a little bit since I'm not sure I understand. The exit block isn't part of the loop after the transformation, meaning that it's not executed as part of the loop. The block appears in the control flow after the exiting block. It's only executed if the loop exits. There shouldn't be any change in blocks executed with this patch.

I think by placing the loop-exit after loop exiting, the structurizer will wire the loop-exit inside the loop. I have add some note based on one lit test to explain the divergent loop exits case, hope it would help.



================
Comment at: llvm/test/Transforms/StructurizeCFG/improve-order.ll:10
+
+define void @reorder_loop(i1 %PredEntry, i1 %PredA, i1 %PredC) {
+; CHECK-LABEL: @reorder_loop(
----------------
For this example, the block `B` and `D` are loop exits. Before this change, they are placed outside of the loop after structurization, so they will only start executing after all the threads in a wave exit the loop. But with this change, they appear inside the loop after structurization. By putting the exits inside the loop, if part of the threads in a wave exit the loop into `B`, then these threads will start executing `B` while other threads continue executing the blocks that have been inside the thread-level loop before structurization. This basically describe the wave execution when loop exit condition is divergent. Before this change, the loop-exits will only be executed once after all the threads exit the loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123231



More information about the llvm-commits mailing list