[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
This commit is contained in:
Felipe de Azevedo Piovezan 2022-07-28 14:56:52 -07:00 committed by Adrian Prantl
parent 31760e8189
commit 58526b2d2b
2 changed files with 7 additions and 1 deletions

View File

@ -111,6 +111,8 @@ MachineInstrBuilder MachineIRBuilder::buildConstDbgValue(const Constant &C,
MIB.addImm(CI->getZExtValue());
} else if (auto *CFP = dyn_cast<ConstantFP>(NumericConstant)) {
MIB.addFPImm(CFP);
} else if (isa<ConstantPointerNull>(NumericConstant)) {
MIB.addImm(0);
} else {
// Insert $noreg if we didn't find a usable constant and had to drop it.
MIB.addReg(Register());

View File

@ -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