Index: llvm/lib/CodeGen/LiveDebugVariables.cpp =================================================================== --- llvm/lib/CodeGen/LiveDebugVariables.cpp +++ llvm/lib/CodeGen/LiveDebugVariables.cpp @@ -1642,14 +1642,28 @@ const DILocalVariable *Variable, const MachineOperand &LocOp, const DIExpression *Expr, DebugLoc &dl) { + if (!LocOp.isReg()) + return false; + MachineBasicBlock::reverse_iterator it = std::next(MachineBasicBlock::reverse_iterator(MI)); while (it != MBB->rend()) { - if (!it->isDebugValue()) - return false; + if (!it->isDebugValue()) { + if (it->isMetaInstruction()) { + it = std::next(it); + continue; + } + + const auto *TRI = MI.getMF()->getSubtarget().getRegisterInfo(); + if (it->modifiesRegister(LocOp.getReg(), TRI)) + return false; + + it = std::next(it); + continue; + } MachineOperand &loc = it->getDebugOperand(0); - if (Variable == it->getDebugVariable() && loc.isReg() && LocOp.isReg() && + if (Variable == it->getDebugVariable() && loc.isReg() && loc.getReg() == LocOp.getReg() && Expr == it->getDebugExpression() && dl == it->getDebugLoc()) { LLVM_DEBUG(llvm::dbgs() << "\navoiding duplicated "; it->dump();); Index: llvm/test/CodeGen/PowerPC/non-debug-mi-search-frspxsrsp.ll =================================================================== --- llvm/test/CodeGen/PowerPC/non-debug-mi-search-frspxsrsp.ll +++ llvm/test/CodeGen/PowerPC/non-debug-mi-search-frspxsrsp.ll @@ -29,7 +29,6 @@ ; CHECK-NEXT: xvcvdpsp 34, 0 ; CHECK-NEXT: xvcvdpsp 35, 1 ; CHECK-NEXT: vmrgew 2, 2, 3 -; CHECK-NEXT: #DEBUG_VALUE: test:Vptr <- $x4 ; CHECK-NEXT: .loc 1 3 9 is_stmt 0 ; CHECK-NEXT: stvx 2, 0, 4 ; CHECK-NEXT: .loc 1 4 1 is_stmt 1