[PATCH] D86634: [AMDGPU] SILowerControlFlow::optimizeEndCF should remove empty basic block

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 17:20:27 PDT 2020


arsenm added a comment.

Should also add a few cases with other empty block situations, including with debug info.

Also should add an example where the original problem occurred



================
Comment at: llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp:617
       MI->eraseFromParent();
+      if (MBB.size() == 1 && MBB.begin()->getOpcode() == AMDGPU::S_BRANCH) {
+        MachineBasicBlock *Succ = MBB.begin()->getOperand(0).getMBB();
----------------
rampitec wrote:
> It will work differently with and without debug info. Imagine that you have a DBG_VALUE in that block, its size will not be 1 anymore. You also need a mir test axactly the same as you are using but with the DBG_VALUE in that block.
> 
> Besides in most cases there is no S_BRANCH at the end, just a fall through to successor.
what if the block is truly empty?

Should also move all of this to a separate function


================
Comment at: llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp:624-625
+        for (auto P : Preds) {
+          P->removeSuccessor(&MBB);
+          P->addSuccessor(Succ);
+          MachineBasicBlock::iterator I(P->getFirstInstrTerminator());
----------------
replaceSuccessor


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

https://reviews.llvm.org/D86634



More information about the llvm-commits mailing list