summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 842ea8b4b88..481e40612c3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -268,11 +268,9 @@ Instruction *InstCombiner::commonCastTransforms(CastInst &CI) {
// the second cast (CI). CSrc will then have a good chance of being dead.
auto *Ty = CI.getType();
auto *Res = CastInst::Create(NewOpc, CSrc->getOperand(0), Ty);
- // Replace debug users of the eliminable cast by emitting debug values
- // which refer to the new cast.
- if (Ty->isIntegerTy() || Ty->isPointerTy())
- // TODO: Support floats and vectors (see DW_OP_convert, fragment).
- insertReplacementDbgValues(*CSrc, *Res, *std::next(CI.getIterator()));
+ // Point debug users of the dying cast to the new one.
+ if (CSrc->hasOneUse())
+ replaceAllDbgUsesWith(*CSrc, *Res, CI, DT);
return Res;
}
}
@@ -1079,16 +1077,10 @@ Instruction *InstCombiner::visitZExt(ZExtInst &CI) {
Value *Res = EvaluateInDifferentType(Src, DestTy, false);
assert(Res->getType() == DestTy);
- // When DestTy is integer, try to preserve any debug values referring
- // to the zext being replaced.
- // TODO: This should work for vectors as well, possibly via the use
- // of DWARF fragments.
- if (DestTy->isIntegerTy()) {
- insertReplacementDbgValues(
- *Src, *Res, CI, [](DbgInfoIntrinsic &OldDII) -> DIExpression * {
- return OldDII.getExpression();
- });
- }
+ // Preserve debug values referring to Src if the zext is its last use.
+ if (auto *SrcOp = dyn_cast<Instruction>(Src))
+ if (SrcOp->hasOneUse())
+ replaceAllDbgUsesWith(*SrcOp, *Res, CI, DT);
uint32_t SrcBitsKept = SrcTy->getScalarSizeInBits()-BitsToClear;
uint32_t DestBitSize = DestTy->getScalarSizeInBits();
OpenPOWER on IntegriCloud