xref: /llvm-project/llvm/test/Transforms/InferAddressSpaces/AMDGPU/debug-info.ll (revision 5651af896c3df30da9edd101b1fb17c00de6636d)
1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s
2
3; check that the debug locations are correctly propagated
4
5@lds = internal unnamed_addr addrspace(3) global [648 x double] undef, align 8
6
7; CHECK-LABEL: @load_global_from_flat(
8; CHECK-NEXT: %tmp0 = addrspacecast ptr %generic_scalar to ptr addrspace(1), !dbg ![[DEBUG_LOC_TMP0:[0-9]+]]
9; CHECK-NEXT: %tmp1 = load float, ptr addrspace(1) %tmp0, align 4, !dbg ![[DEBUG_LOC_TMP1:[0-9]+]]
10; CHECK-NEXT: ret float %tmp1, !dbg ![[DEBUG_LOC_RET:[0-9]+]]
11define float @load_global_from_flat(ptr %generic_scalar) #0 !dbg !5 {
12  %tmp0 = addrspacecast ptr %generic_scalar to ptr addrspace(1), !dbg !8
13  %tmp1 = load float, ptr addrspace(1) %tmp0, align 4, !dbg !9
14  ret float %tmp1, !dbg !10
15}
16
17; CHECK-LABEL: @simplified_constexpr_gep_addrspacecast(
18; CHECK: %gep0 = getelementptr inbounds double, ptr addrspace(3) getelementptr inbounds ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384), i64 %idx0, !dbg ![[DEBUG_LOC_GEP0:[0-9]+]]
19; CHECK-NEXT: store double 1.000000e+00, ptr addrspace(3) %gep0, align 8, !dbg ![[DEBUG_LOC_STORE_GEP0:[0-9]+]]
20define void @simplified_constexpr_gep_addrspacecast(i64 %idx0, i64 %idx1) #0 !dbg !11 {
21  %gep0 = getelementptr inbounds double, ptr addrspacecast (ptr addrspace(3) getelementptr inbounds ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384) to ptr), i64 %idx0, !dbg !12
22  %asc = addrspacecast ptr %gep0 to ptr addrspace(3), !dbg !13
23  store double 1.000000e+00, ptr addrspace(3) %asc, align 8, !dbg !14
24  ret void, !dbg !15
25}
26
27; CHECK-LABEL: @objectsize_group_to_flat_i32(
28; CHECK: %val = call i32 @llvm.objectsize.i32.p3(ptr addrspace(3) %group.ptr, i1 true, i1 false, i1 false), !dbg ![[DEBUG_LOC_VAL:[0-9]+]]
29define i32 @objectsize_group_to_flat_i32(ptr addrspace(3) %group.ptr) #0 !dbg !16 {
30  %cast = addrspacecast ptr addrspace(3) %group.ptr to ptr, !dbg !17
31  %val = call i32 @llvm.objectsize.i32.p0(ptr %cast, i1 true, i1 false, i1 false), !dbg !18
32  ret i32 %val, !dbg !19
33}
34
35; CHECK-LABEL: @memset_group_to_flat(
36; CHECK: call void @llvm.memset.p3.i64(ptr addrspace(3) align 4 %group.ptr, i8 4, i64 32, i1 false), !dbg ![[DEBUG_LOC_MEMSET_CAST:[0-9]+]]
37define amdgpu_kernel void @memset_group_to_flat(ptr addrspace(3) %group.ptr, i32 %y) #0 !dbg !20 {
38  %cast = addrspacecast ptr addrspace(3) %group.ptr to ptr, !dbg !21
39  call void @llvm.memset.p0.i64(ptr align 4 %cast, i8 4, i64 32, i1 false), !dbg !22, !tbaa !23, !alias.scope !26, !noalias !29
40  ret void, !dbg !31
41}
42
43; CHECK-LABEL: @ptrmask_cast_global_to_flat(
44; CHECK-NEXT:    [[PTRMASK:%.*]] = call ptr addrspace(1) @llvm.ptrmask.p1.i64(ptr addrspace(1) %src.ptr, i64 %mask), !dbg ![[DEBUG_LOC_PTRMASK:[0-9]+]]
45; CHECK-NEXT:    %load = load i8, ptr addrspace(1) [[PTRMASK]], align 1, !dbg ![[DEBUG_LOC_LOAD:[0-9]+]]
46define i8 @ptrmask_cast_global_to_flat(ptr addrspace(1) %src.ptr, i64 %mask) #0 !dbg !32 {
47  %cast = addrspacecast ptr addrspace(1) %src.ptr to ptr, !dbg !33
48  %masked = call ptr @llvm.ptrmask.p0.i64(ptr %cast, i64 %mask), !dbg !34
49  %load = load i8, ptr %masked, !dbg !35
50  ret i8 %load, !dbg !36
51}
52
53; the new addrspacecast gets the debug location from it user (in this case, the gep)
54; CHECK-LABEL: @assume_addresspace(
55; CHECK: [[ASCAST:%.*]] = addrspacecast ptr %p to ptr addrspace(3), !dbg ![[DEBUG_LOC_ARRAYIDX:[0-9]+]]
56; CHECK-NEXT: %arrayidx = getelementptr inbounds float, ptr addrspace(3) [[ASCAST]], i64 %x64, !dbg ![[DEBUG_LOC_ARRAYIDX]]
57; CHECK-NEXT: %arrayidx.load = load float, ptr addrspace(3) %arrayidx, align 4, !dbg ![[DEBUG_LOC_ARRAYIDX_LOAD:[0-9]+]]
58define float @assume_addresspace(ptr %p) !dbg !37 {
59entry:
60  %is_shared = call i1 @llvm.amdgcn.is.shared(ptr %p), !dbg !39
61  tail call void @llvm.assume(i1 %is_shared), !dbg !40
62  %x32 = tail call i32 @llvm.amdgcn.workitem.id.x(), !dbg !41
63  %x64 = zext i32 %x32 to i64, !dbg !42
64  %arrayidx = getelementptr inbounds float, ptr %p, i64 %x64, !dbg !43
65  %arrayidx.load = load float, ptr %arrayidx, align 4, !dbg !44
66  ret float %arrayidx.load, !dbg !45
67}
68
69declare i32 @llvm.objectsize.i32.p0(ptr, i1 immarg, i1 immarg, i1 immarg) #1
70declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2
71declare ptr @llvm.ptrmask.p0.i64(ptr, i64) #3
72declare i1 @llvm.amdgcn.is.shared(ptr nocapture) #4
73declare i32 @llvm.amdgcn.workitem.id.x() #4
74declare void @llvm.assume(i1)
75
76attributes #0 = { nounwind }
77attributes #1 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
78attributes #2 = { argmemonly nocallback nofree nounwind willreturn writeonly }
79attributes #3 = { nounwind readnone speculatable willreturn }
80attributes #4 = { nounwind readnone speculatable }
81
82!llvm.dbg.cu = !{!0}
83!llvm.debugify = !{!2, !3}
84!llvm.module.flags = !{!4}
85
86; CHECK: ![[DEBUG_LOC_TMP0]] = !DILocation(line: 1, column: 1,
87; CHECK: ![[DEBUG_LOC_TMP1]] = !DILocation(line: 2, column: 1,
88; CHECK: ![[DEBUG_LOC_RET]] = !DILocation(line: 3, column: 1,
89; CHECK: ![[DEBUG_LOC_GEP0]] = !DILocation(line: 4, column: 1,
90; CHECK: ![[DEBUG_LOC_STORE_GEP0]] = !DILocation(line: 6, column: 1,
91; CHECK: ![[DEBUG_LOC_VAL]] = !DILocation(line: 9, column: 1,
92; CHECK: ![[DEBUG_LOC_MEMSET_CAST]] = !DILocation(line: 12, column: 1,
93; CHECK: ![[DEBUG_LOC_PTRMASK]] = !DILocation(line: 15, column: 1,
94; CHECK: ![[DEBUG_LOC_LOAD]] = !DILocation(line: 16, column: 1,
95; CHECK: ![[DEBUG_LOC_ARRAYIDX]] = !DILocation(line: 23, column: 1,
96; CHECK: ![[DEBUG_LOC_ARRAYIDX_LOAD]] = !DILocation(line: 24, column: 1,
97
98!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
99!1 = !DIFile(filename: "debug_info.pre.ll", directory: "/")
100!2 = !{i32 13}
101!3 = !{i32 0}
102!4 = !{i32 2, !"Debug Info Version", i32 3}
103!5 = distinct !DISubprogram(name: "load_global_from_flat", linkageName: "load_global_from_flat", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !7)
104!6 = !DISubroutineType(types: !7)
105!7 = !{}
106!8 = !DILocation(line: 1, column: 1, scope: !5)
107!9 = !DILocation(line: 2, column: 1, scope: !5)
108!10 = !DILocation(line: 3, column: 1, scope: !5)
109!11 = distinct !DISubprogram(name: "simplified_constexpr_gep_addrspacecast", linkageName: "simplified_constexpr_gep_addrspacecast", scope: null, file: !1, line: 4, type: !6, scopeLine: 4, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !7)
110!12 = !DILocation(line: 4, column: 1, scope: !11)
111!13 = !DILocation(line: 5, column: 1, scope: !11)
112!14 = !DILocation(line: 6, column: 1, scope: !11)
113!15 = !DILocation(line: 7, column: 1, scope: !11)
114!16 = distinct !DISubprogram(name: "objectsize_group_to_flat_i32", linkageName: "objectsize_group_to_flat_i32", scope: null, file: !1, line: 8, type: !6, scopeLine: 8, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !7)
115!17 = !DILocation(line: 8, column: 1, scope: !16)
116!18 = !DILocation(line: 9, column: 1, scope: !16)
117!19 = !DILocation(line: 10, column: 1, scope: !16)
118!20 = distinct !DISubprogram(name: "memset_group_to_flat", linkageName: "memset_group_to_flat", scope: null, file: !1, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !7)
119!21 = !DILocation(line: 11, column: 1, scope: !20)
120!22 = !DILocation(line: 12, column: 1, scope: !20)
121!23 = !{!24, !24, i64 0}
122!24 = !{!"A", !25}
123!25 = !{!"tbaa root"}
124!26 = !{!27}
125!27 = distinct !{!27, !28, !"some scope 1"}
126!28 = distinct !{!28, !"some domain"}
127!29 = !{!30}
128!30 = distinct !{!30, !28, !"some scope 2"}
129!31 = !DILocation(line: 13, column: 1, scope: !20)
130!32 = distinct !DISubprogram(name: "ptrmask_cast_global_to_flat", linkageName: "ptrmask_cast_global_to_flat", scope: null, file: !1, line: 14, type: !6, scopeLine: 14, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !7)
131!33 = !DILocation(line: 14, column: 1, scope: !32)
132!34 = !DILocation(line: 15, column: 1, scope: !32)
133!35 = !DILocation(line: 16, column: 1, scope: !32)
134!36 = !DILocation(line: 17, column: 1, scope: !32)
135!37 = distinct !DISubprogram(name: "assume_addresspace", linkageName: "assume_addresspace", scope: null, file: !1, line: 18, type: !6, scopeLine: 18, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !7)
136!38 = !DILocation(line: 18, column: 1, scope: !37)
137!39 = !DILocation(line: 19, column: 1, scope: !37)
138!40 = !DILocation(line: 20, column: 1, scope: !37)
139!41 = !DILocation(line: 21, column: 1, scope: !37)
140!42 = !DILocation(line: 22, column: 1, scope: !37)
141!43 = !DILocation(line: 23, column: 1, scope: !37)
142!44 = !DILocation(line: 24, column: 1, scope: !37)
143!45 = !DILocation(line: 25, column: 1, scope: !37)