diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -5804,6 +5804,26 @@ if (!Op) return false; + // If the expression refers to the entry value of an Argument, use the + // corresponding livein physical register. As per the Verifier, this is only + // allowed for swiftasync Arguments. + if (Op->isReg() && Expr->isEntryValue()) { + assert(Arg->hasAttribute(Attribute::AttrKind::SwiftAsync)); + auto OpReg = Op->getReg(); + for (auto [PhysReg, VirtReg] : FuncInfo.RegInfo->liveins()) + if (OpReg == VirtReg || OpReg == PhysReg) { + SDDbgValue *SDV = DAG.getVRegDbgValue( + Variable, Expr, PhysReg, + Kind != FuncArgumentDbgValueKind::Value /*is indirect*/, DL, + SDNodeOrder); + DAG.AddDbgValue(SDV, false /*treat as dbg.declare byval parameter*/); + return true; + } + LLVM_DEBUG(dbgs() << "Dropping dbg.value: expression is entry_value but " + "couldn't find a physical register\n"); + return true; + } + assert(Variable->isValidLocationForIntrinsic(DL) && "Expected inlined-at fields to agree"); MachineInstr *NewMI = nullptr; diff --git a/llvm/test/CodeGen/AArch64/dbg-value-swift-async.ll b/llvm/test/CodeGen/AArch64/dbg-value-swift-async.ll --- a/llvm/test/CodeGen/AArch64/dbg-value-swift-async.ll +++ b/llvm/test/CodeGen/AArch64/dbg-value-swift-async.ll @@ -1,4 +1,5 @@ ; RUN: llc -O0 -global-isel -stop-after=irtranslator -verify-machineinstrs %s -o - | FileCheck %s +; RUN: llc -O0 -fast-isel=false -global-isel=false -stop-after=finalize-isel %s -o - | FileCheck %s ; CHECK-NOT: DBG_VALUE ; CHECK: DBG_VALUE $x22, $noreg, !{{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)