diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h --- a/llvm/include/llvm/IR/IntrinsicInst.h +++ b/llvm/include/llvm/IR/IntrinsicInst.h @@ -440,6 +440,13 @@ } void setAssignId(DIAssignID *New); void setAddress(Value *V); + /// Kill the address component. + void setKillAddress(); + /// Check whether this kills the address component. This doesn't take into + /// account the position of the intrinsic, therefore a returned value of false + /// does not guarentee the address is a valid location for the variable at the + /// intrinsic's position in IR. + bool isKillAddress() const; void setValue(Value *V); /// \name Casting methods /// @{ diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp --- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp +++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp @@ -1263,7 +1263,11 @@ const auto *DAI = cast(Source); // Check the address hasn't been dropped (e.g. the debug uses may not have // been replaced before deleting a Value). - if (Value *Val = DAI->getAddress()) { + if (DAI->isKillAddress()) { + // The address isn't valid so treat this as a non-memory def. + Kind = LocKind::Val; + } else { + Value *Val = DAI->getAddress(); DIExpression *Expr = DAI->getAddressExpression(); assert(!Expr->getFragmentInfo() && "fragment info should be stored in value-expression only"); @@ -1279,9 +1283,6 @@ walkToAllocaAndPrependOffsetDeref(Layout, Val, Expr); Emit(Val, Expr); return; - } else { - // The address isn't valid so treat this as a non-memory def. - Kind = LocKind::Val; } } @@ -1483,11 +1484,10 @@ // that an assignment happened here, and we know that specific assignment // was the last one to take place in memory for this variable. LocKind Kind; - if (isa(DAI.getAddress())) { - // Address may be undef to indicate that although the store does take - // place, this part of the original store has been elided. + if (DAI.isKillAddress()) { LLVM_DEBUG( - dbgs() << "Val, Stack matches Debug program but address is undef\n";); + dbgs() + << "Val, Stack matches Debug program but address is killed\n";); Kind = LocKind::Val; } else { LLVM_DEBUG(dbgs() << "Mem, Stack matches Debug program\n";); diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -212,6 +212,17 @@ MetadataAsValue::get(getContext(), ValueAsMetadata::get(V))); } +void DbgAssignIntrinsic::setKillAddress() { + if (isKillAddress()) + return; + setAddress(UndefValue::get(getAddress()->getType())); +} + +bool DbgAssignIntrinsic::isKillAddress() const { + Value *Addr = getAddress(); + return !Addr || isa(Addr); +} + void DbgAssignIntrinsic::setValue(Value *V) { setOperand(OpValue, MetadataAsValue::get(getContext(), ValueAsMetadata::get(V))); diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -520,7 +520,7 @@ LinkToNothing = DIAssignID::getDistinct(Inst->getContext()); NewAssign->setAssignId(LinkToNothing); NewAssign->setExpression(CreateDeadFragExpr()); - NewAssign->setAddress(UndefValue::get(DAI->getAddress()->getType())); + NewAssign->setKillAddress(); } } diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1842,7 +1842,7 @@ DAI->setAddress(NewV); DAI->setAddressExpression(SalvagedExpr); } else { - DAI->setAddress(UndefValue::get(I->getType())); + DAI->setKillAddress(); } }