summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDaniel Berlin <dberlin@dberlin.org>2017-01-30 17:06:55 +0000
committerDaniel Berlin <dberlin@dberlin.org>2017-01-30 17:06:55 +0000
commite19f0e01a80f3ce46c3eae9a90293ca222c7062d (patch)
tree0c56ab629836b233b389d5f87e0f68e23acc12de /llvm/lib
parent098998aef02a853f3cadb64245a4b25fe75219cd (diff)
downloadbcm5719-llvm-e19f0e01a80f3ce46c3eae9a90293ca222c7062d.tar.gz
bcm5719-llvm-e19f0e01a80f3ce46c3eae9a90293ca222c7062d.zip
Revert "NewGVN: Make unreachable blocks be marked with unreachable"
This reverts commit r293196 Besides making things look nicer, ATM, we'd like to preserve analysis more than we'd like to destroy the CFG. We'll probably revisit in the future llvm-svn: 293501
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/NewGVN.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index c17b9f7fcf2..259a4eade0d 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -2106,21 +2106,26 @@ void NewGVN::deleteInstructionsInBlock(BasicBlock *BB) {
DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
++NumGVNBlocksDeleted;
- // Change to unreachable does not handle destroying phi nodes. We just replace
- // the users with undef.
- if (BB->empty())
+ // Check to see if there are non-terminating instructions to delete.
+ if (isa<TerminatorInst>(BB->begin()))
return;
- auto BBI = BB->begin();
- while (auto *Phi = dyn_cast<PHINode>(BBI)) {
- Phi->replaceAllUsesWith(UndefValue::get(Phi->getType()));
- ++BBI;
- }
- Instruction *ToKill = &*BBI;
- // Nothing but phi nodes, so nothing left to remove.
- if (!ToKill)
- return;
- NumGVNInstrDeleted += changeToUnreachable(ToKill, false);
+ // Delete the instructions backwards, as it has a reduced likelihood of having
+ // to update as many def-use and use-def chains. Start after the terminator.
+ auto StartPoint = BB->rbegin();
+ ++StartPoint;
+ // Note that we explicitly recalculate BB->rend() on each iteration,
+ // as it may change when we remove the first instruction.
+ for (BasicBlock::reverse_iterator I(StartPoint); I != BB->rend();) {
+ Instruction &Inst = *I++;
+ if (!Inst.use_empty())
+ Inst.replaceAllUsesWith(UndefValue::get(Inst.getType()));
+ if (isa<LandingPadInst>(Inst))
+ continue;
+
+ Inst.eraseFromParent();
+ ++NumGVNInstrDeleted;
+ }
}
void NewGVN::markInstructionForDeletion(Instruction *I) {
OpenPOWER on IntegriCloud