1 ; Confirm that the line number for the for.body.preheader block
2 ; branch is the the start of the loop.
4 ; RUN: opt -simplifycfg -loop-simplify -S <%s | FileCheck %s
6 ; CHECK: for.body.preheader:
7 ; CHECK-NEXT: br label %for.body, !dbg ![[DL:[0-9]+]]
8 ; CHECK: ![[DL]] = !DILocation(line: 8,
10 ; This IR can be generated by running:
11 ; clang src.cpp -O0 -g -S -emit-llvm -Xclang -disable-O0-optnone -o - | \
12 ; opt -O2 -S -opt-bisect-limit=27 -o -
14 ; Where src.cpp contains:
15 ; int foo(int count, int *bar)
17 ; if (count + 1 > 256)
22 ; for (int j = 0; j < count; j++) {
30 define dso_local i32 @"foo"(i32 %count, i32* nocapture readonly %bar) local_unnamed_addr !dbg !8 {
32 %cmp = icmp sgt i32 %count, 255, !dbg !16
33 br i1 %cmp, label %return, label %for.cond.preheader, !dbg !16
35 for.cond.preheader: ; preds = %entry
36 %cmp16 = icmp slt i32 0, %count, !dbg !19
37 br i1 %cmp16, label %for.body.lr.ph, label %return.loopexit, !dbg !19
39 for.body.lr.ph: ; preds = %for.cond.preheader
40 br label %for.body, !dbg !19
42 for.body: ; preds = %for.body.lr.ph, %for.body
43 %j.08 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
44 %ret.07 = phi i32 [ %count, %for.body.lr.ph ], [ %add2, %for.body ]
45 %0 = zext i32 %j.08 to i64, !dbg !22
46 %arrayidx = getelementptr inbounds i32, i32* %bar, i64 %0, !dbg !22
47 %1 = load i32, i32* %arrayidx, align 4, !dbg !22
48 %add2 = add nsw i32 %1, %ret.07, !dbg !27
49 %inc = add nuw nsw i32 %j.08, 1, !dbg !28
50 %cmp1 = icmp slt i32 %inc, %count, !dbg !19
51 br i1 %cmp1, label %for.body, label %for.cond.return.loopexit_crit_edge, !dbg !19, !llvm.loop !29
53 for.cond.return.loopexit_crit_edge: ; preds = %for.body
54 %split = phi i32 [ %add2, %for.body ]
55 br label %return.loopexit, !dbg !19
57 return.loopexit: ; preds = %for.cond.return.loopexit_crit_edge, %for.cond.preheader
58 %ret.0.lcssa = phi i32 [ %split, %for.cond.return.loopexit_crit_edge ], [ %count, %for.cond.preheader ], !dbg !31
59 br label %return, !dbg !32
61 return: ; preds = %return.loopexit, %entry
62 %retval.0 = phi i32 [ 0, %entry ], [ %ret.0.lcssa, %return.loopexit ], !dbg !31
63 ret i32 %retval.0, !dbg !32
67 !llvm.module.flags = !{!3, !4, !5, !6}
70 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
71 !1 = !DIFile(filename: "src.cpp", directory: "")
73 !3 = !{i32 2, !"CodeView", i32 1}
74 !4 = !{i32 2, !"Debug Info Version", i32 3}
75 !5 = !{i32 1, !"wchar_size", i32 2}
76 !6 = !{i32 7, !"PIC Level", i32 2}
78 !8 = distinct !DISubprogram(name: "foo", linkageName: "?foo@@YAHHPEAH@Z", scope: !1, file: !1, line: 1, type: !9, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
79 !9 = !DISubroutineType(types: !10)
80 !10 = !{!11, !11, !12}
81 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
82 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
83 !13 = !DILocalVariable(name: "bar", arg: 2, scope: !8, file: !1, line: 1, type: !12)
84 !14 = !DILocation(line: 1, scope: !8)
85 !15 = !DILocalVariable(name: "count", arg: 1, scope: !8, file: !1, line: 1, type: !11)
86 !16 = !DILocation(line: 3, scope: !8)
87 !17 = !DILocalVariable(name: "j", scope: !18, file: !1, line: 8, type: !11)
88 !18 = distinct !DILexicalBlock(scope: !8, file: !1, line: 8)
89 !19 = !DILocation(line: 8, scope: !18)
90 !20 = !DILocalVariable(name: "ret", scope: !8, file: !1, line: 6, type: !11)
91 !21 = !DILocation(line: 6, scope: !8)
92 !22 = !DILocation(line: 9, scope: !23)
93 !23 = distinct !DILexicalBlock(scope: !24, file: !1, line: 8)
94 !24 = distinct !DILexicalBlock(scope: !18, file: !1, line: 8)
95 !25 = !DILocalVariable(name: "tmp", scope: !8, file: !1, line: 7, type: !11)
96 !26 = !DILocation(line: 7, scope: !8)
97 !27 = !DILocation(line: 10, scope: !23)
98 !28 = !DILocation(line: 8, scope: !24)
99 !29 = distinct !{!29, !19, !30}
100 !30 = !DILocation(line: 11, scope: !18)
101 !31 = !DILocation(line: 0, scope: !8)
102 !32 = !DILocation(line: 14, scope: !8)