103 lines · plain
1; Confirm that the line number for the for.body.preheader block2; branch is the the start of the loop.3 4; RUN: opt -passes=simplifycfg,loop-simplify -simplifycfg-require-and-preserve-domtree=1 -S <%s | FileCheck %s5;6; CHECK: for.body.preheader:7; CHECK-NEXT: br label %for.body, !dbg ![[DL:[0-9]+]]8; CHECK: ![[DL]] = !DILocation(line: 8,9 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 -13;14; Where src.cpp contains:15; int foo(int count, int *bar)16; {17; if (count + 1 > 256)18; return 0;19;20; int ret = count;21; int tmp;22; for (int j = 0; j < count; j++) {23; tmp = bar[j];24; ret += tmp;25; }26;27; return ret;28; }29 30define dso_local i32 @"foo"(i32 %count, ptr nocapture readonly %bar) local_unnamed_addr !dbg !8 {31entry:32 %cmp = icmp sgt i32 %count, 255, !dbg !1633 br i1 %cmp, label %return, label %for.cond.preheader, !dbg !1634 35for.cond.preheader: ; preds = %entry36 %cmp16 = icmp slt i32 0, %count, !dbg !1937 br i1 %cmp16, label %for.body.lr.ph, label %return.loopexit, !dbg !1938 39for.body.lr.ph: ; preds = %for.cond.preheader40 br label %for.body, !dbg !1941 42for.body: ; preds = %for.body.lr.ph, %for.body43 %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 !2246 %arrayidx = getelementptr inbounds i32, ptr %bar, i64 %0, !dbg !2247 %1 = load i32, ptr %arrayidx, align 4, !dbg !2248 %add2 = add nsw i32 %1, %ret.07, !dbg !2749 %inc = add nuw nsw i32 %j.08, 1, !dbg !2850 %cmp1 = icmp slt i32 %inc, %count, !dbg !1951 br i1 %cmp1, label %for.body, label %for.cond.return.loopexit_crit_edge, !dbg !19, !llvm.loop !2952 53for.cond.return.loopexit_crit_edge: ; preds = %for.body54 %split = phi i32 [ %add2, %for.body ]55 br label %return.loopexit, !dbg !1956 57return.loopexit: ; preds = %for.cond.return.loopexit_crit_edge, %for.cond.preheader58 %ret.0.lcssa = phi i32 [ %split, %for.cond.return.loopexit_crit_edge ], [ %count, %for.cond.preheader ], !dbg !3159 br label %return, !dbg !3260 61return: ; preds = %return.loopexit, %entry62 %retval.0 = phi i32 [ 0, %entry ], [ %ret.0.lcssa, %return.loopexit ], !dbg !3163 ret i32 %retval.0, !dbg !3264}65 66!llvm.dbg.cu = !{!0}67!llvm.module.flags = !{!3, !4, !5, !6}68!llvm.ident = !{!7}69 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: "")72!2 = !{}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}77!7 = !{!""}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)103