From 58526b2d2be932e893218857cc47a16fb05cf1c0 Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Thu, 28 Jul 2022 14:56:52 -0700 Subject: [PATCH] [GlobalISel] Handle nullptr constants in dbg.value Currently, the LLVM IR -> MIR translator fails to translate dbg.values whose first argument is a null pointer. However, in other portions of the code, such pointers are always lowered to the constant zero, for example see IRTranslator::Translate(Constant, Register). This patch addresses the limitation by following the same approach of lowering null pointers to zero. A prior test was checking that null pointers were always lowered to $noreg; this test is changed to check for zero, and the previous behavior is now checked by introducing a dbg.value whose first argument is the address of a global variable. Differential Revision: https://reviews.llvm.org/D130721 --- llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp | 2 ++ llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index 7328ea4eed25..85ed9d3ac4d9 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -111,6 +111,8 @@ MachineInstrBuilder MachineIRBuilder::buildConstDbgValue(const Constant &C, MIB.addImm(CI->getZExtValue()); } else if (auto *CFP = dyn_cast(NumericConstant)) { MIB.addFPImm(CFP); + } else if (isa(NumericConstant)) { + MIB.addImm(0); } else { // Insert $noreg if we didn't find a usable constant and had to drop it. MIB.addReg(Register()); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll b/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll index 5573378b087d..a024ad8d2057 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll @@ -25,6 +25,8 @@ entry: ret void, !dbg !15 } +@gv = global i32 zeroinitializer + ; CHECK-LABEL: name: debug_value ; CHECK: [[IN:%[0-9]+]]:_(s32) = COPY $w0 define void @debug_value(i32 %in) #0 !dbg !16 { @@ -38,8 +40,10 @@ define void @debug_value(i32 %in) #0 !dbg !16 { call void @llvm.dbg.value(metadata i32 123, i64 0, metadata !17, metadata !DIExpression()), !dbg !18 ; CHECK: DBG_VALUE float 1.000000e+00, 0, !17, !DIExpression(), debug-location !18 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 +; CHECK: DBG_VALUE 0, 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 $noreg, 0, !17, !DIExpression(), debug-location !18 + call void @llvm.dbg.value(metadata i32* @gv, 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