Skip to content

Commit 5a1d92f

Browse files
committed
[InstCombine] Update debug intrinsics when rewriting allocas
1 parent eb95ab5 commit 5a1d92f

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Instruction *InstCombinerImpl::PromoteCastOfAllocation(BitCastInst &CI,
167167
New->setMetadata(LLVMContext::MD_DIAssignID,
168168
AI.getMetadata(LLVMContext::MD_DIAssignID));
169169

170+
replaceAllDbgUsesWith(AI, *New, *New, DT);
171+
170172
// If the allocation has multiple real uses, insert a cast and change all
171173
// things that used it to use the new cast. This will also hack on CI, but it
172174
// will die soon.

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static bool isDereferenceableForAllocaSize(const Value *V, const AllocaInst *AI,
169169
}
170170

171171
static Instruction *simplifyAllocaArraySize(InstCombinerImpl &IC,
172-
AllocaInst &AI) {
172+
AllocaInst &AI, DominatorTree &DT) {
173173
// Check for array size of 1 (scalar allocation).
174174
if (!AI.isArrayAllocation()) {
175175
// i32 1 is the canonical array size for scalar allocations.
@@ -188,6 +188,8 @@ static Instruction *simplifyAllocaArraySize(InstCombinerImpl &IC,
188188
nullptr, AI.getName());
189189
New->setAlignment(AI.getAlign());
190190

191+
replaceAllDbgUsesWith(AI, *New, *New, DT);
192+
191193
// Scan to the end of the allocation instructions, to skip over a block of
192194
// allocas if possible...also skip interleaved debug info
193195
//
@@ -356,7 +358,7 @@ void PointerReplacer::replacePointer(Instruction &I, Value *V) {
356358
}
357359

358360
Instruction *InstCombinerImpl::visitAllocaInst(AllocaInst &AI) {
359-
if (auto *I = simplifyAllocaArraySize(*this, AI))
361+
if (auto *I = simplifyAllocaArraySize(*this, AI, DT))
360362
return I;
361363

362364
if (AI.getAllocatedType()->isSized()) {

llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/alloca-bitcast.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
; CHECK: entry:
2424
; CHECK-NEXT: %retval = alloca i64, align 8, !DIAssignID ![[ID:[0-9]+]]
2525
; CHECK-NEXT: %tmpcast = bitcast i64* %retval to %struct.c*
26-
; CHECK-NEXT: call void @llvm.dbg.assign(metadata i1 undef, metadata ![[e:[0-9]+]], metadata !DIExpression(), metadata ![[ID]], metadata %struct.c* %tmpcast, metadata !DIExpression()), !dbg
26+
; CHECK-NEXT: call void @llvm.dbg.assign(metadata i1 undef, metadata ![[e:[0-9]+]], metadata !DIExpression(), metadata ![[ID]], metadata i64* %retval, metadata !DIExpression()), !dbg
2727
; CHECK: ![[e]] = !DILocalVariable(name: "e",
2828

2929
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: opt -S --passes=instcombine %s | FileCheck %s
2+
3+
; https://github.com/llvm/llvm-project/issues/56807
4+
%si16 = type { i8, i8 }
5+
6+
declare void @foo(i16* %pixels)
7+
8+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
9+
10+
; CHECK-LABEL: @toplevel(
11+
; CHECK: entry:
12+
; CHECK-NEXT: %pixels = alloca i16
13+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i16* %pixels, metadata ![[MD:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG:[0-9]+]]
14+
; CHECK-NEXT: call void @foo(i16* nonnull %pixels)
15+
; CHECK-NEXT: ret void
16+
define dso_local void @toplevel() {
17+
entry:
18+
%pixels = alloca %si16
19+
call void @llvm.dbg.declare(metadata %si16* %pixels, metadata !11, metadata !DIExpression()), !dbg !12
20+
%arraydecay = bitcast %si16* %pixels to i16*
21+
call void @foo(i16* nonnull %arraydecay)
22+
ret void
23+
}
24+
25+
!llvm.dbg.cu = !{!0}
26+
!llvm.module.flags = !{!3, !4, !5}
27+
28+
29+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.1.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
30+
!1 = !DIFile(filename: "test.cpp", directory: "/path/to/test_cpp")
31+
!2 = !{}
32+
!3 = !{i32 7, !"Dwarf Version", i32 4}
33+
!4 = !{i32 2, !"Debug Info Version", i32 3}
34+
!5 = !{i32 1, !"wchar_size", i32 4}
35+
!7 = distinct !DISubprogram(name: "toplevel", linkageName: "_Z8toplevelv", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
36+
!8 = !DISubroutineType(types: !9)
37+
!9 = !{!10, !10}
38+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
39+
; CHECK: ![[MD]] = !DILocalVariable(name: "pixels"
40+
!11 = !DILocalVariable(name: "pixels", arg: 1, scope: !7, file: !1, line: 9, type: !10)
41+
; CHECK: ![[DBG]] = !DILocation(line: 9, column: 16,
42+
!12 = !DILocation(line: 9, column: 16, scope: !7)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: opt -S --passes=instcombine %s | FileCheck %s
2+
3+
; https://github.com/llvm/llvm-project/issues/56807
4+
declare void @foo(i8* %pixels)
5+
6+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
7+
8+
; CHECK-LABEL: @toplevel(
9+
; CHECK: entry:
10+
; CHECK-NEXT: %pixels1 = alloca [3 x i8], align 1
11+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata [3 x i8]* %pixels1, metadata ![[MD:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG:[0-9]+]]
12+
; CHECK-NEXT: %pixels1.sub = getelementptr inbounds [3 x i8], [3 x i8]* %pixels1, i64 0, i64 0
13+
; CHECK-NEXT: call void @foo(i8* nonnull %pixels1.sub)
14+
; CHECK-NEXT: ret void
15+
define dso_local void @toplevel() {
16+
entry:
17+
%pixels = alloca i8, i32 3
18+
call void @llvm.dbg.declare(metadata i8* %pixels, metadata !11, metadata !DIExpression()), !dbg !12
19+
call void @foo(i8* %pixels)
20+
ret void
21+
}
22+
23+
!llvm.dbg.cu = !{!0}
24+
!llvm.module.flags = !{!3, !4, !5}
25+
26+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.1.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
27+
!1 = !DIFile(filename: "test.cpp", directory: "/path/to/test_cpp")
28+
!2 = !{}
29+
!3 = !{i32 7, !"Dwarf Version", i32 4}
30+
!4 = !{i32 2, !"Debug Info Version", i32 3}
31+
!5 = !{i32 1, !"wchar_size", i32 4}
32+
!7 = distinct !DISubprogram(name: "toplevel", linkageName: "_Z8toplevelv", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
33+
!8 = !DISubroutineType(types: !9)
34+
!9 = !{!10, !10}
35+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
36+
; CHECK: ![[MD]] = !DILocalVariable(name: "pixels"
37+
!11 = !DILocalVariable(name: "pixels", arg: 1, scope: !7, file: !1, line: 9, type: !10)
38+
; CHECK: ![[DBG]] = !DILocation(line: 9, column: 16,
39+
!12 = !DILocation(line: 9, column: 16, scope: !7)
40+

0 commit comments

Comments
 (0)