summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/JumpThreading.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/JumpThreading.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index c2a737d8f9a4..c7d71eb5633e 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -1437,9 +1437,18 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
// AvailablePreds vector as we go so that all of the PHI entries for this
// predecessor use the same bitcast.
Value *&PredV = I->second;
- if (PredV->getType() != LoadI->getType())
+ if (PredV->getType() != LoadI->getType()) {
PredV = CastInst::CreateBitOrPointerCast(
PredV, LoadI->getType(), "", P->getTerminator()->getIterator());
+ // The new cast is producing the value used to replace the load
+ // instruction, so uses the load's debug location. If P does not always
+ // branch to the load BB however then the debug location must be dropped,
+ // as it is hoisted past a conditional branch.
+ DebugLoc DL = P->getTerminator()->getNumSuccessors() == 1
+ ? LoadI->getDebugLoc()
+ : DebugLoc::getDropped();
+ cast<CastInst>(PredV)->setDebugLoc(DL);
+ }
PN->addIncoming(PredV, I->first);
}