Skip to content

Commit 7f01150

Browse files
committed
Add salvageDebugInfo support for truncating/extending ptr/int conversions.
This patch enables debug info salvaging for truncating/extending ptr int conversions. The testcase uncovered a bug in adce, which is addressed separately. rdar://80227769 Differential Revision: https://reviews.llvm.org/D110461 (cherry picked from commit 1b998a5)
1 parent e247502 commit 7f01150

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,12 +1908,19 @@ Value *llvm::salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
19081908
}
19091909

19101910
Type *Type = CI->getType();
1911+
if (Type->isPointerTy())
1912+
Type = DL.getIntPtrType(Type);
19111913
// Casts other than Trunc, SExt, or ZExt to scalar types cannot be salvaged.
19121914
if (Type->isVectorTy() ||
1913-
!(isa<TruncInst>(&I) || isa<SExtInst>(&I) || isa<ZExtInst>(&I)))
1915+
!(isa<TruncInst>(&I) || isa<SExtInst>(&I) || isa<ZExtInst>(&I) ||
1916+
isa<IntToPtrInst>(&I) || isa<PtrToIntInst>(&I)))
19141917
return nullptr;
19151918

1916-
unsigned FromTypeBitSize = FromValue->getType()->getScalarSizeInBits();
1919+
llvm::Type *FromType = FromValue->getType();
1920+
if (FromType->isPointerTy())
1921+
FromType = DL.getIntPtrType(FromType);
1922+
1923+
unsigned FromTypeBitSize = FromType->getScalarSizeInBits();
19171924
unsigned ToTypeBitSize = Type->getScalarSizeInBits();
19181925

19191926
auto ExtOps = DIExpression::getExtOps(FromTypeBitSize, ToTypeBitSize,
@@ -1924,9 +1931,9 @@ Value *llvm::salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
19241931

19251932
if (auto *GEP = dyn_cast<GetElementPtrInst>(&I))
19261933
return getSalvageOpsForGEP(GEP, DL, CurrentLocOps, Ops, AdditionalValues);
1927-
else if (auto *BI = dyn_cast<BinaryOperator>(&I)) {
1934+
if (auto *BI = dyn_cast<BinaryOperator>(&I))
19281935
return getSalvageOpsForBinOp(BI, CurrentLocOps, Ops, AdditionalValues);
1929-
}
1936+
19301937
// *Not* to do: we should not attempt to salvage load instructions,
19311938
// because the validity and lifetime of a dbg.value containing
19321939
// DW_OP_deref becomes difficult to analyze. See PR40628 for examples.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt -adce %s -S -o - | FileCheck %s
2+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
3+
target triple = "x86_64-apple-macosx"
4+
define void @f(i32) !dbg !8 {
5+
entry:
6+
%p_x = inttoptr i32 %0 to i8*
7+
%i_x = ptrtoint i8* %p_x to i32
8+
; CHECK: call void @llvm.dbg.value(metadata i8* undef,
9+
; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
10+
; CHECK-SAME: DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value))
11+
call void @llvm.dbg.value(metadata i32 %i_x, metadata !11, metadata !DIExpression()), !dbg !13
12+
ret void, !dbg !13
13+
}
14+
declare void @llvm.dbg.value(metadata, metadata, metadata)
15+
16+
!llvm.dbg.cu = !{!0}
17+
!llvm.module.flags = !{!3, !4}
18+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug)
19+
!1 = !DIFile(filename: "salavage.c", directory: "/")
20+
!3 = !{i32 2, !"Dwarf Version", i32 4}
21+
!4 = !{i32 2, !"Debug Info Version", i32 3}
22+
!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0)
23+
!9 = !DISubroutineType(types: !10)
24+
!10 = !{null}
25+
!11 = !DILocalVariable(name: "x", scope: !8, file: !1, line: 2, type: !12)
26+
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
27+
!13 = !DILocation(line: 1, column: 1, scope: !8)

0 commit comments

Comments
 (0)