llvm.org GIT mirror llvm / 4ca34ad
Resubmit: [Salvage] Change salvage debug info implementation to use DW_OP_LLVM_convert where needed Fixes issue: https://bugs.llvm.org/show_bug.cgi?id=40645 Previously, LLVM had no functional way of performing casts inside of a DIExpression(), which made salvaging cast instructions other than Noop casts impossible. With the recent addition of DW_OP_LLVM_convert this salvaging is now possible, and so can be used to fix the attached bug as well as any cases where SExt instruction results are lost in the debugging metadata. This patch introduces this fix by expanding the salvage debug info method to cover these cases using the new operator. Differential revision: https://reviews.llvm.org/D61184 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360902 91177308-0d34-0410-b5e6-96231b3b80d8 Stephen Tozer 4 months ago
5 changed file(s) with 50 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
16891689 // No-op casts and zexts are irrelevant for debug info.
16901690 if (CI->isNoopCast(DL) || isa(&I))
16911691 return SrcDIExpr;
1692 return nullptr;
1693 } else if (auto *GEP = dyn_cast(&I)) {
1692
1693 Type *Type = CI->getType();
1694 // Casts other than Trunc or SExt to scalar types cannot be salvaged.
1695 if (Type->isVectorTy() || (!isa(&I) && !isa(&I)))
1696 return nullptr;
1697
1698 Value *FromValue = CI->getOperand(0);
1699 unsigned FromTypeBitSize = FromValue->getType()->getScalarSizeInBits();
1700
1701 unsigned ToTypeBitSize = Type->getScalarSizeInBits();
1702
1703 // The result of the cast will be sign extended iff the instruction is a
1704 // SExt; signedness is otherwise irrelevant on the expression stack.
1705 unsigned Encoding =
1706 isa(&I) ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
1707
1708 return applyOps({dwarf::DW_OP_LLVM_convert, FromTypeBitSize, Encoding,
1709 dwarf::DW_OP_LLVM_convert, ToTypeBitSize, Encoding});
1710 }
1711
1712 if (auto *GEP = dyn_cast(&I)) {
16941713 unsigned BitWidth =
16951714 M.getDataLayout().getIndexSizeInBits(GEP->getPointerAddressSpace());
16961715 // Rewrite a constant GEP into a DIExpression.
0 ; RUN: opt %s -debugify -early-cse -S | FileCheck %s
1 define i32 @foo(i64 %nose, i32 %more) {
2 ; CHECK-LABEL: @foo(
3 ; CHECK: call void @llvm.dbg.value(metadata i64 %nose, metadata [[V1:![0-9]+]], metadata !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned
4 ; CHECK: call void @llvm.dbg.value(metadata i64 %nose.shift, metadata [[V2:![0-9]+]]
5 ; CHECK: call void @llvm.dbg.value(metadata i64 %nose.shift, metadata [[V3:![0-9]+]], metadata !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned
6
7 entry:
8 %nose.trunc = trunc i64 %nose to i32
9 %nose.shift = lshr i64 %nose, 32
10 %nose.trunc.2 = trunc i64 %nose.shift to i32
11 %add = add nsw i32 %more, 1
12 ret i32 %add
13 }
14
15 !llvm.module.flags = !{!0, !1}
16 !llvm.ident = !{!2}
17
18 !0 = !{i32 1, !"wchar_size", i32 2}
19 !1 = !{i32 7, !"PIC Level", i32 2}
20 !2 = !{!"clang version 9.0.0 "}
21
22 ; CHECK: [[V1]] = !DILocalVariable(
23 ; CHECK: [[V2]] = !DILocalVariable(
24 ; CHECK: [[V3]] = !DILocalVariable(
99 %0 = load i8, i8* @a, align 1, !dbg !19, !tbaa !20
1010 %conv = sext i8 %0 to i16, !dbg !19
1111
12 ; CHECK: call void @llvm.dbg.value(metadata i16 undef, metadata !17, metadata !DIExpression()), !dbg !18
12 ; CHECK: call void @llvm.dbg.value(metadata i8 %0, metadata !17, metadata !DIExpression(DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 16, DW_ATE_signed, DW_OP_stack_value)), !dbg !18
1313 ; CHECK-NEXT: call i32 (...) @optimize_me_not()
1414
1515 call void @llvm.dbg.value(metadata i16 %conv, metadata !17, metadata !DIExpression()), !dbg !18
1212 ; we preserve the debug information in the resulting
1313 ; instruction.
1414 ; DBGINFO-LABEL: @mul(
15 ; DBGINFO-NEXT: call void @llvm.dbg.value(metadata i32 %x
16 ; DBGINFO-NEXT: call void @llvm.dbg.value(metadata i32 %y
1517 ; DBGINFO-NEXT: [[C:%.*]] = mul i32 {{.*}}
1618 ; DBGINFO-NEXT: [[D:%.*]] = and i32 {{.*}}
1719 ; DBGINFO-NEXT: call void @llvm.dbg.value(metadata i32 [[C]]
11
22 ; Make sure to update the debug value after dead code elimination.
33 ; CHECK: %call = call signext i8 @b(i32 6), !dbg !39
4 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !30, metadata !DIExpression()), !dbg !38
4 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8 %call, metadata !30, metadata !DIExpression(DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value)), !dbg !38
55
66 @e = common local_unnamed_addr global i8 0, align 1, !dbg !0
77 @c = common local_unnamed_addr global i32 0, align 4, !dbg !6