[all-commits] [llvm/llvm-project] a5641f: [SPIR-V] Add pass to merge convergence region exit...

Nathan Gauër via All-commits all-commits at lists.llvm.org
Mon Jun 3 02:36:17 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a5641f106affc3afb899eee42eb40c2ded81f411
      https://github.com/llvm/llvm-project/commit/a5641f106affc3afb899eee42eb40c2ded81f411
  Author: Nathan Gauër <brioche at google.com>
  Date:   2024-06-03 (Mon, 03 Jun 2024)

  Changed paths:
    M llvm/lib/Target/SPIRV/CMakeLists.txt
    M llvm/lib/Target/SPIRV/SPIRV.h
    M llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
    M llvm/lib/Target/SPIRV/SPIRVInstrInfo.td
    A llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
    M llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
    A llvm/test/CodeGen/SPIRV/structurizer/merge-exit-break.ll
    A llvm/test/CodeGen/SPIRV/structurizer/merge-exit-convergence-in-break.ll
    A llvm/test/CodeGen/SPIRV/structurizer/merge-exit-multiple-break.ll
    A llvm/test/CodeGen/SPIRV/structurizer/merge-exit-simple-white-identity.ll

  Log Message:
  -----------
  [SPIR-V] Add pass to merge convergence region exit targets (#92531)

The structurizer required regions to be SESE: single entry, single exit.
This new pass transforms multiple-exit regions into single-exit regions.

```
      +---+
      | A |
      +---+
      /   \
   +---+ +---+
   | B | | C |  A, B & C belongs to the same convergence region.
   +---+ +---+
     |     |
   +---+ +---+
   | D | | E |  C & D belongs to the parent convergence region.
   +---+ +---+  This means B & C are the exit blocks of the region.
      \   /     And D & E the targets of those exits.
       \ /
        |
      +---+
      | F |
      +---+
```

This pass would assign one value per exit target:
B = 0
C = 1

Then, create one variable per exit block (B, C), and assign it to the
correct value: in B, the variable will have the value 0, and in C, the
value 1.

Then, we'd create a new block H, with a PHI node to gather those 2
variables, and a switch, to route to the correct target.

Finally, the branches in B and C are updated to exit to this new block.

```
      +---+
      | A |
      +---+
      /   \
   +---+ +---+
   | B | | C |
   +---+ +---+
      \   /
      +---+
      | H |
      +---+
      /   \
   +---+ +---+
   | D | | E |
   +---+ +---+
      \   /
       \ /
        |
      +---+
      | F |
      +---+
```

Note: the variable is set depending on the condition used to branch. If
B's terminator was conditional, the variable would be set using a
SELECT.
All internal edges of a region are left intact, only exiting edges are
updated.

---------

Signed-off-by: Nathan Gauër <brioche at google.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list