diff options
author | Orlando Cazalet-Hyams <orlando.hyams@sony.com> | 2019-05-07 15:37:38 +0000 |
---|---|---|
committer | Orlando Cazalet-Hyams <orlando.hyams@sony.com> | 2019-05-07 15:37:38 +0000 |
commit | 78a6062c24dc51180101666b82afa8d7fab920d1 (patch) | |
tree | 7b4b64e5b211da4c39fdd123e8fa6cbe0c3e5467 /llvm/test/Transforms/LoopSimplify | |
parent | eeed7ee2cc7cbd49a906bed05a69140647ebb6d2 (diff) | |
download | bcm5719-llvm-78a6062c24dc51180101666b82afa8d7fab920d1.tar.gz bcm5719-llvm-78a6062c24dc51180101666b82afa8d7fab920d1.zip |
[DebugInfo@O2][LoopVectorize] pr39024: Vectorized code linenos step through loop even after completion
Summary:
Bug: https://bugs.llvm.org/show_bug.cgi?id=39024
The bug reports that a vectorized loop is stepped through 4 times and each step through the loop seemed to show a different path. I found two problems here:
A) An incorrect line number on a preheader block (for.body.preheader) instruction causes a step into the loop before it begins.
B) Instructions in the middle block have different line numbers which give the impression of another iteration.
In this patch I give all of the middle block instructions the line number of the scalar loop latch terminator branch. This seems to provide the smoothest debugging experience because the vectorized loops will always end on this line before dropping into the scalar loop. To solve problem A I have altered llvm::SplitBlockPredecessors to accommodate loop header blocks.
Reviewers: samsonov, vsk, aprantl, probinson, anemet, hfinkel
Reviewed By: hfinkel
Subscribers: bjope, jmellorcrummey, hfinkel, gbedwell, hiraditya, zzheng, llvm-commits
Tags: #llvm, #debug-info
Differential Revision: https://reviews.llvm.org/D60831
llvm-svn: 360162
Diffstat (limited to 'llvm/test/Transforms/LoopSimplify')
-rw-r--r-- | llvm/test/Transforms/LoopSimplify/dbg-loc.ll | 2 | ||||
-rwxr-xr-x | llvm/test/Transforms/LoopSimplify/do-preheader-dbg.ll | 122 | ||||
-rwxr-xr-x | llvm/test/Transforms/LoopSimplify/for-preheader-dbg.ll | 102 |
3 files changed, 225 insertions, 1 deletions
diff --git a/llvm/test/Transforms/LoopSimplify/dbg-loc.ll b/llvm/test/Transforms/LoopSimplify/dbg-loc.ll index efd5e8e71c9..4bc519338cb 100644 --- a/llvm/test/Transforms/LoopSimplify/dbg-loc.ll +++ b/llvm/test/Transforms/LoopSimplify/dbg-loc.ll @@ -72,7 +72,7 @@ eh.resume: ; preds = %catch ; Function Attrs: nounwind readnone declare void @llvm.dbg.value(metadata, metadata, metadata) -; CHECK-DAG: [[PREHEADER_LOC]] = !DILocation(line: 73, column: 27, scope: !{{[0-9]+}}) +; CHECK-DAG: [[PREHEADER_LOC]] = !DILocation(line: 73, column: 13, scope: !{{[0-9]+}}) ; CHECK-DAG: [[LOOPEXIT_LOC]] = !DILocation(line: 75, column: 9, scope: !{{[0-9]+}}) ; CHECK-DAG: [[LPAD_PREHEADER_LOC]] = !DILocation(line: 85, column: 1, scope: !{{[0-9]+}}) diff --git a/llvm/test/Transforms/LoopSimplify/do-preheader-dbg.ll b/llvm/test/Transforms/LoopSimplify/do-preheader-dbg.ll new file mode 100755 index 00000000000..7cacc49cd80 --- /dev/null +++ b/llvm/test/Transforms/LoopSimplify/do-preheader-dbg.ll @@ -0,0 +1,122 @@ +; Confirm that the line number for the do.body.preheader block +; branch is the the start of the loop. + +; RUN: opt -simplifycfg -loop-simplify -keep-loops="false" -S <%s | FileCheck %s + +; CHECK: do.body.preheader: +; CHECK-NEXT: phi +; CHECK-NEXT: phi +; CHECK-NEXT: br label %do.body, !dbg ![[DL:[0-9]+]] +; CHECK: ![[DL]] = !DILocation(line: 4, + +; This IR can be generated by running: +; clang src.cpp -O2 -g -S -emit-llvm -mllvm -opt-bisect-limit=62 -o - +; +; Where src.cpp contains: +; int foo(char *Bytes, int Count) +; { +; int Total = 0; +; do +; Total += Bytes[--Count]; +; while (Count); +; return Total; +; } + +define dso_local i32 @"foo"(i8* nocapture readonly %Bytes, i32 %Count) local_unnamed_addr !dbg !8 { +entry: + %0 = sext i32 %Count to i64, !dbg !10 + %min.iters.check = icmp ult i32 %Count, 8, !dbg !10 + br i1 %min.iters.check, label %do.body.preheader, label %vector.ph, !dbg !10 + +vector.ph: ; preds = %entry + %n.vec = and i64 %0, -8, !dbg !10 + %ind.end = sub nsw i64 %0, %n.vec, !dbg !10 + br label %vector.body, !dbg !10 + +vector.body: ; preds = %vector.body, %vector.ph + %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ] + %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %11, %vector.body ] + %vec.phi5 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %12, %vector.body ] + %1 = xor i64 %index, -1, !dbg !11 + %2 = add i64 %1, %0, !dbg !11 + %3 = getelementptr inbounds i8, i8* %Bytes, i64 %2, !dbg !11 + %4 = getelementptr inbounds i8, i8* %3, i64 -3, !dbg !11 + %5 = bitcast i8* %4 to <4 x i8>*, !dbg !11 + %wide.load = load <4 x i8>, <4 x i8>* %5, align 1, !dbg !11, !tbaa !12 + %reverse = shufflevector <4 x i8> %wide.load, <4 x i8> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>, !dbg !11 + %6 = getelementptr inbounds i8, i8* %3, i64 -4, !dbg !11 + %7 = getelementptr inbounds i8, i8* %6, i64 -3, !dbg !11 + %8 = bitcast i8* %7 to <4 x i8>*, !dbg !11 + %wide.load6 = load <4 x i8>, <4 x i8>* %8, align 1, !dbg !11, !tbaa !12 + %reverse7 = shufflevector <4 x i8> %wide.load6, <4 x i8> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>, !dbg !11 + %9 = sext <4 x i8> %reverse to <4 x i32>, !dbg !11 + %10 = sext <4 x i8> %reverse7 to <4 x i32>, !dbg !11 + %11 = add nsw <4 x i32> %vec.phi, %9, !dbg !11 + %12 = add nsw <4 x i32> %vec.phi5, %10, !dbg !11 + %index.next = add i64 %index, 8 + %13 = icmp eq i64 %index.next, %n.vec + br i1 %13, label %middle.block, label %vector.body, !llvm.loop !15 + +middle.block: ; preds = %vector.body + %.lcssa12 = phi <4 x i32> [ %11, %vector.body ], !dbg !11 + %.lcssa = phi <4 x i32> [ %12, %vector.body ], !dbg !11 + %bin.rdx = add <4 x i32> %.lcssa, %.lcssa12, !dbg !11 + %rdx.shuf = shufflevector <4 x i32> %bin.rdx, <4 x i32> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>, !dbg !11 + %bin.rdx8 = add <4 x i32> %bin.rdx, %rdx.shuf, !dbg !11 + %rdx.shuf9 = shufflevector <4 x i32> %bin.rdx8, <4 x i32> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>, !dbg !11 + %bin.rdx10 = add <4 x i32> %bin.rdx8, %rdx.shuf9, !dbg !11 + %14 = extractelement <4 x i32> %bin.rdx10, i32 0, !dbg !11 + %cmp.n = icmp eq i64 %n.vec, %0 + br i1 %cmp.n, label %do.end, label %do.body.preheader, !dbg !10 + +do.body.preheader: ; preds = %middle.block, %entry + %indvars.iv.ph = phi i64 [ %0, %entry ], [ %ind.end, %middle.block ] + %Total.0.ph = phi i32 [ 0, %entry ], [ %14, %middle.block ] + br label %do.body, !dbg !11 + +do.body: ; preds = %do.body.preheader, %do.body + %indvars.iv = phi i64 [ %indvars.iv.next, %do.body ], [ %indvars.iv.ph, %do.body.preheader ] + %Total.0 = phi i32 [ %add, %do.body ], [ %Total.0.ph, %do.body.preheader ], !dbg !18 + %indvars.iv.next = add nsw i64 %indvars.iv, -1, !dbg !11 + %arrayidx = getelementptr inbounds i8, i8* %Bytes, i64 %indvars.iv.next, !dbg !11 + %15 = load i8, i8* %arrayidx, align 1, !dbg !11, !tbaa !12 + %conv = sext i8 %15 to i32, !dbg !11 + %add = add nsw i32 %Total.0, %conv, !dbg !11 + %16 = icmp eq i64 %indvars.iv.next, 0 + br i1 %16, label %do.end.loopexit, label %do.body, !dbg !11, !llvm.loop !19 + +do.end.loopexit: ; preds = %do.body + %add.lcssa11 = phi i32 [ %add, %do.body ], !dbg !11 + br label %do.end, !dbg !21 + +do.end: ; preds = %do.end.loopexit, %middle.block + %add.lcssa = phi i32 [ %14, %middle.block ], [ %add.lcssa11, %do.end.loopexit ], !dbg !11 + ret i32 %add.lcssa, !dbg !21 +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "src2.cpp", directory: "") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{i32 7, !"PIC Level", i32 2} +!7 = !{!""} +!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !9, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!9 = !DISubroutineType(types: !2) +!10 = !DILocation(line: 4, scope: !8) +!11 = !DILocation(line: 5, scope: !8) +!12 = !{!13, !13, i64 0} +!13 = !{!"omnipotent char", !14, i64 0} +!14 = !{!"Simple C++ TBAA"} +!15 = distinct !{!15, !10, !16, !17} +!16 = !DILocation(line: 6, scope: !8) +!17 = !{!"llvm.loop.isvectorized", i32 1} +!18 = !DILocation(line: 0, scope: !8) +!19 = distinct !{!19, !10, !16, !20, !17} +!20 = !{!"llvm.loop.unroll.runtime.disable"} +!21 = !DILocation(line: 7, scope: !8) diff --git a/llvm/test/Transforms/LoopSimplify/for-preheader-dbg.ll b/llvm/test/Transforms/LoopSimplify/for-preheader-dbg.ll new file mode 100755 index 00000000000..439b72024c3 --- /dev/null +++ b/llvm/test/Transforms/LoopSimplify/for-preheader-dbg.ll @@ -0,0 +1,102 @@ +; Confirm that the line number for the for.body.preheader block +; branch is the the start of the loop. + +; RUN: opt -simplifycfg -loop-simplify -S <%s | FileCheck %s +; +; CHECK: for.body.preheader: +; CHECK-NEXT: br label %for.body, !dbg ![[DL:[0-9]+]] +; CHECK: ![[DL]] = !DILocation(line: 8, + +; This IR can be generated by running: +; clang src.cpp -O0 -g -S -emit-llvm -Xclang -disable-O0-optnone -o - | \ +; opt -O2 -S -opt-bisect-limit=27 -o - +; +; Where src.cpp contains: +; int foo(int count, int *bar) +; { +; if (count + 1 > 256) +; return 0; +; +; int ret = count; +; int tmp; +; for (int j = 0; j < count; j++) { +; tmp = bar[j]; +; ret += tmp; +; } +; +; return ret; +; } + +define dso_local i32 @"foo"(i32 %count, i32* nocapture readonly %bar) local_unnamed_addr !dbg !8 { +entry: + %cmp = icmp sgt i32 %count, 255, !dbg !16 + br i1 %cmp, label %return, label %for.cond.preheader, !dbg !16 + +for.cond.preheader: ; preds = %entry + %cmp16 = icmp slt i32 0, %count, !dbg !19 + br i1 %cmp16, label %for.body.lr.ph, label %return.loopexit, !dbg !19 + +for.body.lr.ph: ; preds = %for.cond.preheader + br label %for.body, !dbg !19 + +for.body: ; preds = %for.body.lr.ph, %for.body + %j.08 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ] + %ret.07 = phi i32 [ %count, %for.body.lr.ph ], [ %add2, %for.body ] + %0 = zext i32 %j.08 to i64, !dbg !22 + %arrayidx = getelementptr inbounds i32, i32* %bar, i64 %0, !dbg !22 + %1 = load i32, i32* %arrayidx, align 4, !dbg !22 + %add2 = add nsw i32 %1, %ret.07, !dbg !27 + %inc = add nuw nsw i32 %j.08, 1, !dbg !28 + %cmp1 = icmp slt i32 %inc, %count, !dbg !19 + br i1 %cmp1, label %for.body, label %for.cond.return.loopexit_crit_edge, !dbg !19, !llvm.loop !29 + +for.cond.return.loopexit_crit_edge: ; preds = %for.body + %split = phi i32 [ %add2, %for.body ] + br label %return.loopexit, !dbg !19 + +return.loopexit: ; preds = %for.cond.return.loopexit_crit_edge, %for.cond.preheader + %ret.0.lcssa = phi i32 [ %split, %for.cond.return.loopexit_crit_edge ], [ %count, %for.cond.preheader ], !dbg !31 + br label %return, !dbg !32 + +return: ; preds = %return.loopexit, %entry + %retval.0 = phi i32 [ 0, %entry ], [ %ret.0.lcssa, %return.loopexit ], !dbg !31 + ret i32 %retval.0, !dbg !32 +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "src.cpp", directory: "") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{i32 7, !"PIC Level", i32 2} +!7 = !{!""} +!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) +!9 = !DISubroutineType(types: !10) +!10 = !{!11, !11, !12} +!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) +!13 = !DILocalVariable(name: "bar", arg: 2, scope: !8, file: !1, line: 1, type: !12) +!14 = !DILocation(line: 1, scope: !8) +!15 = !DILocalVariable(name: "count", arg: 1, scope: !8, file: !1, line: 1, type: !11) +!16 = !DILocation(line: 3, scope: !8) +!17 = !DILocalVariable(name: "j", scope: !18, file: !1, line: 8, type: !11) +!18 = distinct !DILexicalBlock(scope: !8, file: !1, line: 8) +!19 = !DILocation(line: 8, scope: !18) +!20 = !DILocalVariable(name: "ret", scope: !8, file: !1, line: 6, type: !11) +!21 = !DILocation(line: 6, scope: !8) +!22 = !DILocation(line: 9, scope: !23) +!23 = distinct !DILexicalBlock(scope: !24, file: !1, line: 8) +!24 = distinct !DILexicalBlock(scope: !18, file: !1, line: 8) +!25 = !DILocalVariable(name: "tmp", scope: !8, file: !1, line: 7, type: !11) +!26 = !DILocation(line: 7, scope: !8) +!27 = !DILocation(line: 10, scope: !23) +!28 = !DILocation(line: 8, scope: !24) +!29 = distinct !{!29, !19, !30} +!30 = !DILocation(line: 11, scope: !18) +!31 = !DILocation(line: 0, scope: !8) +!32 = !DILocation(line: 14, scope: !8) |