1 ; RUN: llc -stop-after=machine-sink < %s | FileCheck %s
4 ; 1 extern int bar(int x);
6 ; 3 int foo(int *begin, int *end) {
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.
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 ADD64ri8 [[VREG3]], 4
30 ; CHECK: SUB64rr [[VREG1]], [[VREG4]]
31 ; CHECK-NEXT: JCC_1 {{.*}}, debug-location [[DLOC]]{{$}}
32 ; CHECK-NEXT: JMP_1 {{.*}}, debug-location [[DLOC]]{{$}}
34 target triple = "x86_64-unknown-linux-gnu"
36 define i32 @foo(i32* readonly %begin, i32* readnone %end) !dbg !4 {
38 %cmp6 = icmp eq i32* %begin, %end, !dbg !9
39 br i1 %cmp6, label %for.end, label %for.body.preheader, !dbg !12
41 for.body.preheader: ; preds = %entry
42 br label %for.body, !dbg !13
44 for.body: ; preds = %for.body.preheader, %for.body
45 %ret.08 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]
46 %i.07 = phi i32* [ %incdec.ptr, %for.body ], [ %begin, %for.body.preheader ]
47 %0 = load i32, i32* %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, i32* %i.07, i64 1, !dbg !21
51 %cmp = icmp eq i32* %incdec.ptr, %end, !dbg !9
52 br i1 %cmp, label %for.end.loopexit, label %for.body, !dbg !12, !llvm.loop !22
54 for.end.loopexit: ; preds = %for.body
55 br label %for.end, !dbg !24
57 for.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
65 !llvm.module.flags = !{!2, !3}
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)
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)