144 lines · plain
1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s2 3; check that the debug locations are correctly propagated4 5@lds = internal unnamed_addr addrspace(3) global [648 x double] poison, align 86 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 !813 %tmp1 = load float, ptr addrspace(1) %tmp0, align 4, !dbg !914 ret float %tmp1, !dbg !1015}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 !1222 %asc = addrspacecast ptr %gep0 to ptr addrspace(3), !dbg !1323 store double 1.000000e+00, ptr addrspace(3) %asc, align 8, !dbg !1424 ret void, !dbg !1525}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 !1731 %val = call i32 @llvm.objectsize.i32.p0(ptr %cast, i1 true, i1 false, i1 false), !dbg !1832 ret i32 %val, !dbg !1933}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 !2139 call void @llvm.memset.p0.i64(ptr align 4 %cast, i8 4, i64 32, i1 false), !dbg !22, !tbaa !23, !alias.scope !26, !noalias !2940 ret void, !dbg !3141}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 !3348 %masked = call ptr @llvm.ptrmask.p0.i64(ptr %cast, i64 %mask), !dbg !3449 %load = load i8, ptr %masked, !dbg !3550 ret i8 %load, !dbg !3651}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 !3961 tail call void @llvm.assume(i1 %is_shared), !dbg !4062 %x32 = tail call i32 @llvm.amdgcn.workitem.id.x(), !dbg !4163 %x64 = zext i32 %x32 to i64, !dbg !4264 %arrayidx = getelementptr inbounds float, ptr %p, i64 %x64, !dbg !4365 %arrayidx.load = load float, ptr %arrayidx, align 4, !dbg !4466 ret float %arrayidx.load, !dbg !4567}68 69declare i32 @llvm.objectsize.i32.p0(ptr, i1 immarg, i1 immarg, i1 immarg) #170declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #271declare ptr @llvm.ptrmask.p0.i64(ptr, i64) #372declare i1 @llvm.amdgcn.is.shared(ptr nocapture) #473declare i32 @llvm.amdgcn.workitem.id.x() #474declare 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)144