diff options
author | Adrian Prantl <aprantl@apple.com> | 2017-11-01 20:43:30 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2017-11-01 20:43:30 +0000 |
commit | d60f34c20a2f31335c8d5626e87376f358f73b92 (patch) | |
tree | a54280794bf2c9335239a12d083315d9be09ecb4 /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | |
parent | ca9075272bddaa369da0111fbe75b2a14f2a241c (diff) | |
download | bcm5719-llvm-d60f34c20a2f31335c8d5626e87376f358f73b92.tar.gz bcm5719-llvm-d60f34c20a2f31335c8d5626e87376f358f73b92.zip |
loop-rotate: eliminate duplicate debug intrinsics after splicing.
Fixes part of PR35113.
This reapplies r317105 with an additional check for isa<Instruction>
as found by the bots.
llvm-svn: 317120
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index c9b0f208180..606bd8bacca 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -23,11 +23,13 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Type.h" #include "llvm/IR/User.h" @@ -142,8 +144,16 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT, } // Begin by getting rid of unneeded PHIs. - if (isa<PHINode>(BB->front())) + SmallVector<Value *, 4> IncomingValues; + if (isa<PHINode>(BB->front())) { + for (auto &I : *BB) + if (PHINode *PN = dyn_cast<PHINode>(&I)) { + if (PN->getIncomingValue(0) != PN) + IncomingValues.push_back(PN->getIncomingValue(0)); + } else + break; FoldSingleEntryPHINodes(BB, MemDep); + } // Delete the unconditional branch from the predecessor... PredBB->getInstList().pop_back(); @@ -155,6 +165,21 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT, // Move all definitions in the successor to the predecessor... PredBB->getInstList().splice(PredBB->end(), BB->getInstList()); + // Eliminate duplicate dbg.values describing the entry PHI node post-splice. + for (auto *Incoming : IncomingValues) { + if (isa<Instruction>(Incoming)) { + SmallVector<DbgValueInst *, 2> DbgValues; + SmallDenseSet<std::pair<DILocalVariable *, DIExpression *>, 2> + DbgValueSet; + llvm::findDbgValues(DbgValues, Incoming); + for (auto &DVI : DbgValues) { + auto R = DbgValueSet.insert({DVI->getVariable(), DVI->getExpression()}); + if (!R.second) + DVI->eraseFromParent(); + } + } + } + // Inherit predecessors name if it exists. if (!PredBB->hasName()) PredBB->takeName(BB); |