1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=fiji < %s | FileCheck %s
3 ; Make sure we do not crash during scheduling when DBG_VALUE is the first
4 ; instruction in the basic block.
6 ; LLVM IR generated with the following command and OpenCL source:
8 ; $clang -cl-std=CL2.0 -g -O2 -target amdgcn-amd-amdhsa -S -emit-llvm <path-to-file>
10 ; kernel void kernel1(global int *A, global int *B) {
19 declare void @llvm.dbg.value(metadata, metadata, metadata)
21 ; CHECK-LABEL: {{^}}kernel1:
22 define amdgpu_kernel void @kernel1(
23 i32 addrspace(1)* nocapture readonly %A,
24 i32 addrspace(1)* nocapture %B) !dbg !7 {
26 tail call void @llvm.dbg.value(metadata i32 addrspace(1)* %A, metadata !13, metadata !19), !dbg !20
27 tail call void @llvm.dbg.value(metadata i32 addrspace(1)* %B, metadata !14, metadata !19), !dbg !21
28 %0 = load i32, i32 addrspace(1)* %A, align 4, !dbg !22, !tbaa !24
29 %cmp = icmp eq i32 %0, 1, !dbg !28
30 br i1 %cmp, label %if.then, label %if.end, !dbg !29
32 if.then: ; preds = %entry
33 store i32 12, i32 addrspace(1)* %B, align 4, !dbg !30, !tbaa !24
34 %.pr = load i32, i32 addrspace(1)* %A, align 4, !dbg !32, !tbaa !24
35 br label %if.end, !dbg !34
37 if.end: ; preds = %if.then, %entry
38 %1 = phi i32 [ %.pr, %if.then ], [ %0, %entry ], !dbg !32
39 %cmp1 = icmp eq i32 %1, 2, !dbg !35
40 br i1 %cmp1, label %if.then2, label %if.end3, !dbg !36
42 if.then2: ; preds = %if.end
43 store i32 13, i32 addrspace(1)* %B, align 4, !dbg !37, !tbaa !24
44 br label %if.end3, !dbg !39
46 if.end3: ; preds = %if.then2, %if.end
51 !opencl.ocl.version = !{!3}
52 !llvm.module.flags = !{!4, !5}
55 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
56 !1 = !DIFile(filename: "dbg-value-sched-crash.cl", directory: "/some/random/directory")
59 !4 = !{i32 2, !"Dwarf Version", i32 2}
60 !5 = !{i32 2, !"Debug Info Version", i32 3}
61 !6 = !{!"clang version 4.0 "}
62 !7 = distinct !DISubprogram(name: "kernel1", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
63 !8 = !DISubroutineType(types: !9)
64 !9 = !{null, !10, !10}
65 !10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
66 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
68 !13 = !DILocalVariable(name: "A", arg: 1, scope: !7, file: !1, line: 1, type: !10)
69 !14 = !DILocalVariable(name: "B", arg: 2, scope: !7, file: !1, line: 1, type: !10)
71 !16 = !{!"none", !"none"}
72 !17 = !{!"int*", !"int*"}
74 !19 = !DIExpression(DW_OP_constu, 1, DW_OP_swap, DW_OP_xderef)
75 !20 = !DILocation(line: 1, column: 33, scope: !7)
76 !21 = !DILocation(line: 1, column: 48, scope: !7)
77 !22 = !DILocation(line: 2, column: 7, scope: !23)
78 !23 = distinct !DILexicalBlock(scope: !7, file: !1, line: 2, column: 7)
79 !24 = !{!25, !25, i64 0}
80 !25 = !{!"int", !26, i64 0}
81 !26 = !{!"omnipotent char", !27, i64 0}
82 !27 = !{!"Simple C/C++ TBAA"}
83 !28 = !DILocation(line: 2, column: 10, scope: !23)
84 !29 = !DILocation(line: 2, column: 7, scope: !7)
85 !30 = !DILocation(line: 3, column: 8, scope: !31)
86 !31 = distinct !DILexicalBlock(scope: !23, file: !1, line: 2, column: 16)
87 !32 = !DILocation(line: 5, column: 7, scope: !33)
88 !33 = distinct !DILexicalBlock(scope: !7, file: !1, line: 5, column: 7)
89 !34 = !DILocation(line: 4, column: 3, scope: !31)
90 !35 = !DILocation(line: 5, column: 10, scope: !33)
91 !36 = !DILocation(line: 5, column: 7, scope: !7)
92 !37 = !DILocation(line: 6, column: 8, scope: !38)
93 !38 = distinct !DILexicalBlock(scope: !33, file: !1, line: 5, column: 16)
94 !39 = !DILocation(line: 7, column: 3, scope: !38)
95 !40 = !DILocation(line: 8, column: 1, scope: !7)