diff options
| author | Vedant Kumar <vsk@apple.com> | 2018-11-18 00:29:58 +0000 |
|---|---|---|
| committer | Vedant Kumar <vsk@apple.com> | 2018-11-18 00:29:58 +0000 |
| commit | 35f504c1131a8de2c12b70d36222667803981b67 (patch) | |
| tree | 8f1b0d04693de0d28033b760ff1918c8b6139711 /llvm/lib | |
| parent | 5b9bb25c45446460ac140111a0d05dbcbf8072e3 (diff) | |
| download | bcm5719-llvm-35f504c1131a8de2c12b70d36222667803981b67.tar.gz bcm5719-llvm-35f504c1131a8de2c12b70d36222667803981b67.zip | |
[CorrelatedValuePropagation] Preserve debug locations (PR38178)
Fix all of the missing debug location errors in CVP found by debugify.
This includes the missing-location-after-udiv-truncation case described
in llvm.org/PR38178.
llvm-svn: 347147
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 99402985f28..826df6c6ab9 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -430,23 +430,21 @@ static bool willNotOverflow(IntrinsicInst *II, LazyValueInfo *LVI) { } static void processOverflowIntrinsic(IntrinsicInst *II) { + IRBuilder<> B(II); Value *NewOp = nullptr; switch (II->getIntrinsicID()) { default: llvm_unreachable("Unexpected instruction."); case Intrinsic::uadd_with_overflow: case Intrinsic::sadd_with_overflow: - NewOp = BinaryOperator::CreateAdd(II->getOperand(0), II->getOperand(1), - II->getName(), II); + NewOp = B.CreateAdd(II->getOperand(0), II->getOperand(1), II->getName()); break; case Intrinsic::usub_with_overflow: case Intrinsic::ssub_with_overflow: - NewOp = BinaryOperator::CreateSub(II->getOperand(0), II->getOperand(1), - II->getName(), II); + NewOp = B.CreateSub(II->getOperand(0), II->getOperand(1), II->getName()); break; } ++NumOverflows; - IRBuilder<> B(II); Value *NewI = B.CreateInsertValue(UndefValue::get(II->getType()), NewOp, 0); NewI = B.CreateInsertValue(NewI, ConstantInt::getFalse(II->getContext()), 1); II->replaceAllUsesWith(NewI); @@ -528,17 +526,17 @@ static bool processUDivOrURem(BinaryOperator *Instr, LazyValueInfo *LVI) { return false; ++NumUDivs; + IRBuilder<> B{Instr}; auto *TruncTy = Type::getIntNTy(Instr->getContext(), NewWidth); - auto *LHS = CastInst::Create(Instruction::Trunc, Instr->getOperand(0), TruncTy, - Instr->getName() + ".lhs.trunc", Instr); - auto *RHS = CastInst::Create(Instruction::Trunc, Instr->getOperand(1), TruncTy, - Instr->getName() + ".rhs.trunc", Instr); - auto *BO = - BinaryOperator::Create(Instr->getOpcode(), LHS, RHS, Instr->getName(), Instr); - auto *Zext = CastInst::Create(Instruction::ZExt, BO, Instr->getType(), - Instr->getName() + ".zext", Instr); - if (BO->getOpcode() == Instruction::UDiv) - BO->setIsExact(Instr->isExact()); + auto *LHS = B.CreateTruncOrBitCast(Instr->getOperand(0), TruncTy, + Instr->getName() + ".lhs.trunc"); + auto *RHS = B.CreateTruncOrBitCast(Instr->getOperand(1), TruncTy, + Instr->getName() + ".rhs.trunc"); + auto *BO = B.CreateBinOp(Instr->getOpcode(), LHS, RHS, Instr->getName()); + auto *Zext = B.CreateZExt(BO, Instr->getType(), Instr->getName() + ".zext"); + if (auto *BinOp = dyn_cast<BinaryOperator>(BO)) + if (BinOp->getOpcode() == Instruction::UDiv) + BinOp->setIsExact(Instr->isExact()); Instr->replaceAllUsesWith(Zext); Instr->eraseFromParent(); @@ -552,6 +550,7 @@ static bool processSRem(BinaryOperator *SDI, LazyValueInfo *LVI) { ++NumSRems; auto *BO = BinaryOperator::CreateURem(SDI->getOperand(0), SDI->getOperand(1), SDI->getName(), SDI); + BO->setDebugLoc(SDI->getDebugLoc()); SDI->replaceAllUsesWith(BO); SDI->eraseFromParent(); @@ -573,6 +572,7 @@ static bool processSDiv(BinaryOperator *SDI, LazyValueInfo *LVI) { ++NumSDivs; auto *BO = BinaryOperator::CreateUDiv(SDI->getOperand(0), SDI->getOperand(1), SDI->getName(), SDI); + BO->setDebugLoc(SDI->getDebugLoc()); BO->setIsExact(SDI->isExact()); SDI->replaceAllUsesWith(BO); SDI->eraseFromParent(); @@ -595,6 +595,7 @@ static bool processAShr(BinaryOperator *SDI, LazyValueInfo *LVI) { ++NumAShrs; auto *BO = BinaryOperator::CreateLShr(SDI->getOperand(0), SDI->getOperand(1), SDI->getName(), SDI); + BO->setDebugLoc(SDI->getDebugLoc()); BO->setIsExact(SDI->isExact()); SDI->replaceAllUsesWith(BO); SDI->eraseFromParent(); |

