xref: /llvm-project/llvm/test/CodeGen/X86/update-terminator-debugloc.ll (revision c81a121f3f230cfe468b6def6d2904b4aefb855b)
1; RUN: llc -stop-after=machine-sink < %s | FileCheck %s
2;
3; test code:
4;  1 extern int bar(int x);
5;  2
6;  3 int foo(int *begin, int *end) {
7;  4   int *i;
8;  5   int ret = 0;
9;  6   for (
10;  7       i = begin ;
11;  8       i != end ;
12;  9       i++)
13; 10   {
14; 11       ret += bar(*i);
15; 12   }
16; 13   return ret;
17; 14 }
18;
19; With the test code, LLVM-IR below shows that loop-control branches have a
20; debug location of line 6 (branches in entry and for.body block). Make sure that
21; these debug locations are propaged correctly to lowered instructions.
22;
23; CHECK: [[DLOC:![0-9]+]] = !DILocation(line: 6
24; CHECK-DAG: [[VREG1:%[^ ]+]]:gr64 = COPY $rsi
25; CHECK-DAG: [[VREG2:%[^ ]+]]:gr64 = COPY $rdi
26; CHECK: SUB64rr [[VREG2]], [[VREG1]]
27; CHECK-NEXT: JCC_1 {{.*}}, debug-location [[DLOC]]{{$}}
28; CHECK: [[VREG3:%[^ ]+]]:gr64 = PHI [[VREG2]]
29; CHECK: [[VREG4:%[^ ]+]]:gr64 = nuw ADD64ri32 [[VREG3]], 4
30; CHECK: SUB64rr [[VREG4]], [[VREG1]]
31; CHECK-NEXT: JCC_1 {{.*}}, debug-location [[DLOC]]{{$}}
32; CHECK-NEXT: JMP_1 {{.*}}, debug-location [[DLOC]]{{$}}
33
34target triple = "x86_64-unknown-linux-gnu"
35
36define i32 @foo(ptr readonly %begin, ptr readnone %end) !dbg !4 {
37entry:
38  %cmp6 = icmp eq ptr %begin, %end, !dbg !9
39  br i1 %cmp6, label %for.end, label %for.body.preheader, !dbg !12
40
41for.body.preheader:                               ; preds = %entry
42  br label %for.body, !dbg !13
43
44for.body:                                         ; preds = %for.body.preheader, %for.body
45  %ret.08 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]
46  %i.07 = phi ptr [ %incdec.ptr, %for.body ], [ %begin, %for.body.preheader ]
47  %0 = load i32, ptr %i.07, align 4, !dbg !13, !tbaa !15
48  %call = tail call i32 @bar(i32 %0), !dbg !19
49  %add = add nsw i32 %call, %ret.08, !dbg !20
50  %incdec.ptr = getelementptr inbounds i32, ptr %i.07, i64 1, !dbg !21
51  %cmp = icmp eq ptr %incdec.ptr, %end, !dbg !9
52  br i1 %cmp, label %for.end.loopexit, label %for.body, !dbg !12, !llvm.loop !22
53
54for.end.loopexit:                                 ; preds = %for.body
55  br label %for.end, !dbg !24
56
57for.end:                                          ; preds = %for.end.loopexit, %entry
58  %ret.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ]
59  ret i32 %ret.0.lcssa, !dbg !24
60}
61
62declare i32 @bar(i32)
63
64!llvm.dbg.cu = !{!0}
65!llvm.module.flags = !{!2, !3}
66
67!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
68!1 = !DIFile(filename: "foo.c", directory: "b/")
69!2 = !{i32 2, !"Dwarf Version", i32 4}
70!3 = !{i32 2, !"Debug Info Version", i32 3}
71!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
72!5 = !DISubroutineType(types: !6)
73!6 = !{!7, !8, !8}
74!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
75!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
76!9 = !DILocation(line: 8, column: 9, scope: !10)
77!10 = distinct !DILexicalBlock(scope: !11, file: !1, line: 6, column: 3)
78!11 = distinct !DILexicalBlock(scope: !4, file: !1, line: 6, column: 3)
79!12 = !DILocation(line: 6, column: 3, scope: !11)
80!13 = !DILocation(line: 11, column: 18, scope: !14)
81!14 = distinct !DILexicalBlock(scope: !10, file: !1, line: 10, column: 3)
82!15 = !{!16, !16, i64 0}
83!16 = !{!"int", !17, i64 0}
84!17 = !{!"omnipotent char", !18, i64 0}
85!18 = !{!"Simple C/C++ TBAA"}
86!19 = !DILocation(line: 11, column: 14, scope: !14)
87!20 = !DILocation(line: 11, column: 11, scope: !14)
88!21 = !DILocation(line: 9, column: 8, scope: !10)
89!22 = distinct !{!22, !12, !23}
90!23 = !DILocation(line: 12, column: 3, scope: !11)
91!24 = !DILocation(line: 13, column: 3, scope: !4)
92