[PATCH] D130721: [GlobalISel] Handle nullptr constants in dbg.value

Felipe de Azevedo Piovezan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 11:25:17 PDT 2022


fdeazeve created this revision.
Herald added subscribers: hiraditya, rovka.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130721

Files:
  llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll


Index: llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
+++ llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
@@ -25,6 +25,8 @@
   ret void, !dbg !15
 }
 
+ at 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 @@
   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
Index: llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -111,6 +111,8 @@
       MIB.addImm(CI->getZExtValue());
   } else if (auto *CFP = dyn_cast<ConstantFP>(NumericConstant)) {
     MIB.addFPImm(CFP);
+  } else if (isa<llvm::ConstantPointerNull>(NumericConstant)) {
+    MIB.addImm(0);
   } else {
     // Insert $noreg if we didn't find a usable constant and had to drop it.
     MIB.addReg(Register());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130721.448392.patch
Type: text/x-patch
Size: 1981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220728/739b7319/attachment.bin>


More information about the llvm-commits mailing list