diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -96,12 +96,20 @@ cast(Variable)->isValidLocationForIntrinsic(getDL()) && "Expected inlined-at fields to agree"); auto MIB = buildInstrNoInsert(TargetOpcode::DBG_VALUE); - if (auto *CI = dyn_cast(&C)) { + + auto *NumericConstant = [&] { + if (const auto *CE = dyn_cast(&C)) + if (CE->getOpcode() == Instruction::IntToPtr) + return cast(CE->getOperand(0)); + return &C; + }(); + + if (auto *CI = dyn_cast(NumericConstant)) { if (CI->getBitWidth() > 64) MIB.addCImm(CI); else MIB.addImm(CI->getZExtValue()); - } else if (auto *CFP = dyn_cast(&C)) { + } else if (auto *CFP = dyn_cast(NumericConstant)) { MIB.addFPImm(CFP); } else { // Insert $noreg if we didn't find a usable constant and had to drop it. diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll b/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll --- a/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll @@ -40,6 +40,8 @@ call void @llvm.dbg.value(metadata float 1.000000e+00, i64 0, metadata !17, metadata !DIExpression()), !dbg !18 ; CHECK: DBG_VALUE $noreg, 0, !17, !DIExpression(), debug-location !18 call void @llvm.dbg.value(metadata i32* null, i64 0, metadata !17, metadata !DIExpression()), !dbg !18 +; CHECK: DBG_VALUE 42, 0, !17, !DIExpression(), debug-location !18 + call void @llvm.dbg.value(metadata i32* inttoptr (i64 42 to i32*), i64 0, metadata !17, metadata !DIExpression()), !dbg !18 ret void }