aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2017-11-01 17:28:47 +0000
committerAdrian Prantl <aprantl@apple.com>2017-11-01 17:28:47 +0000
commitb627acd0ce2969cac9b5af819c658aabc89d9e87 (patch)
tree94f6273730195c629c7c1aaf4edf5e84ef9ede4a /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
parent369a7ecc56d3c4ceceefb98fcf898feda34f72f2 (diff)
downloadllvm-b627acd0ce2969cac9b5af819c658aabc89d9e87.zip
llvm-b627acd0ce2969cac9b5af819c658aabc89d9e87.tar.gz
llvm-b627acd0ce2969cac9b5af819c658aabc89d9e87.tar.bz2
loop-rotate: eliminate duplicate debug intrinsics after splicing.
Fixes part of PR35113. llvm-svn: 317105
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BasicBlockUtils.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index c9b0f20..34e204a 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,18 @@ 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) {
+ 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);