[PATCH] D116714: AMDGPU: Fix LiveVariables error after optimizing VGPR ranges

Ruiling, Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 7 17:22:16 PST 2022


ruiling added inline comments.


================
Comment at: llvm/lib/Target/AMDGPU/SIOptimizeVGPRLiveRange.cpp:389
 
   for (MachineBasicBlock *MBB : depth_first_ext(ThenEntry, Visited)) {
     if (MBB == Flow)
----------------
ruiling wrote:
> A pre-order walk over the blocks should more match the need here. the dfs walk does not work if we meet `Flow` block first, thus skipping some blocks in the THEN region. Using "continue" will make the traversal going all the way to the return block of the function.
I take a second look, the order of the blocks does not matter here. We can use any order of traversal to collect all the blocks in the THEN region before this for-loop. We can use something like below to get all the blocks. (I choose SetVector mainly to keep the later iteration over the blocks is still in some kind of deterministic order. DenseSet also works.)

```
  SetVector<MachineBasicBlock*> Blocks;
  SmallVector<MachineBasicBlock *> WorkList;

  WorkList.push_back(If);
  while (!WorkList.empty()) {
    auto *MBB = WorkList.pop_back_val(); 
    for (auto *Succ : MBB->successors()) {
      if (Succ != Flow && !Blocks.contains(Succ)) {
        WorkList.push_back(Succ);
        Blocks.insert(Succ);
      }
    }
  }

```


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

https://reviews.llvm.org/D116714



More information about the llvm-commits mailing list