diff options
| author | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-13 05:27:09 +0000 |
|---|---|---|
| committer | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-13 05:27:09 +0000 |
| commit | 4056e7f02a407971ef837bb2eff4724cfd475c4d (patch) | |
| tree | be034726e06b9cfaf998f0cc98af2e044950348f /llvm/lib/Transforms | |
| parent | 4868841ee4ff9a32ce1021ef3335e81e19b4f354 (diff) | |
| download | bcm5719-llvm-4056e7f02a407971ef837bb2eff4724cfd475c4d.tar.gz bcm5719-llvm-4056e7f02a407971ef837bb2eff4724cfd475c4d.zip | |
[Attributor][FIX] Avoid splitting blocks if possible
Before, we eagerly split blocks even if it was not necessary, e.g., they
had a single unreachable instruction and only a single predecessor.
llvm-svn: 374703
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 08675de6cb1..2778daf9fab 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -2139,8 +2139,6 @@ struct AAIsDeadImpl : public AAIsDead { BasicBlock *BB = I->getParent(); Instruction *SplitPos = I->getNextNode(); // TODO: mark stuff before unreachable instructions as dead. - if (isa_and_nonnull<UnreachableInst>(SplitPos)) - continue; if (auto *II = dyn_cast<InvokeInst>(I)) { // If we keep the invoke the split position is at the beginning of the @@ -2183,15 +2181,23 @@ struct AAIsDeadImpl : public AAIsDead { // also manifest. assert(!NormalDestBB->isLandingPad() && "Expected the normal destination not to be a landingpad!"); - BasicBlock *SplitBB = - SplitBlockPredecessors(NormalDestBB, {BB}, ".dead"); - // The split block is live even if it contains only an unreachable - // instruction at the end. - assumeLive(A, *SplitBB); - SplitPos = SplitBB->getTerminator(); + if (NormalDestBB->getUniquePredecessor() == BB) { + assumeLive(A, *NormalDestBB); + } else { + BasicBlock *SplitBB = + SplitBlockPredecessors(NormalDestBB, {BB}, ".dead"); + // The split block is live even if it contains only an unreachable + // instruction at the end. + assumeLive(A, *SplitBB); + SplitPos = SplitBB->getTerminator(); + HasChanged = ChangeStatus::CHANGED; + } } } + if (isa_and_nonnull<UnreachableInst>(SplitPos)) + continue; + BB = SplitPos->getParent(); SplitBlock(BB, SplitPos); changeToUnreachable(BB->getTerminator(), /* UseLLVMTrap */ false); |

