diff options
author | Amara Emerson <amara@apple.com> | 2021-10-05 17:41:21 -0700 |
---|---|---|
committer | Amara Emerson <amara@apple.com> | 2021-10-05 23:06:22 -0700 |
commit | 6bc64e24c38a42f2797ee64c78cb2d42b245b59e (patch) | |
tree | 760bda91147aa25ccf7ac7f59833fec71dd22ec2 /llvm/lib | |
parent | cb89d3739db746ea50eb50b7208e689126394391 (diff) | |
download | llvm-6bc64e24c38a42f2797ee64c78cb2d42b245b59e.zip llvm-6bc64e24c38a42f2797ee64c78cb2d42b245b59e.tar.gz llvm-6bc64e24c38a42f2797ee64c78cb2d42b245b59e.tar.bz2 |
[GlobalISel] Clear unreachable blocks' contents after selection.
If these blocks are unreachable, then we can discard all of the instructions.
However, keep the block around because it may have an address taken or the
block may have a stale reference from a PHI somewhere. Instead of finding
those PHIs and fixing them up, just leave the block empty.
Differential Revision: https://reviews.llvm.org/D111201
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp index 75a8f03..77d9cd7 100644 --- a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -130,9 +130,12 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) { // Until then, keep track of the number of blocks to assert that we don't. const size_t NumBlocks = MF.size(); #endif + // Keep track of selected blocks, so we can delete unreachable ones later. + DenseSet<MachineBasicBlock *> SelectedBlocks; for (MachineBasicBlock *MBB : post_order(&MF)) { ISel->CurMBB = MBB; + SelectedBlocks.insert(MBB); if (MBB->empty()) continue; @@ -205,6 +208,15 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) { if (MBB.empty()) continue; + if (!SelectedBlocks.contains(&MBB)) { + // This is an unreachable block and therefore hasn't been selected, since + // the main selection loop above uses a postorder block traversal. + // We delete all the instructions in this block since it's unreachable. + MBB.clear(); + // Don't delete the block in case the block has it's address taken or is + // still being referenced by a phi somewhere. + continue; + } // Try to find redundant copies b/w vregs of the same register class. bool ReachedBegin = false; for (auto MII = std::prev(MBB.end()), Begin = MBB.begin(); !ReachedBegin;) { |