From 1251cac62af531401f3012e1975a973ac5c7e3b1 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Wed, 19 Jun 2019 10:50:47 +0000 Subject: [PATCH] [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. I have set up a separate review D61933 for a fix which is required for this patch. Reviewers: samsonov, vsk, aprantl, probinson, anemet, hfinkel, jmorse Reviewed By: hfinkel, jmorse Subscribers: jmorse, javed.absar, eraman, kcc, bjope, jmellorcrummey, hfinkel, gbedwell, hiraditya, zzheng, llvm-commits Tags: #llvm, #debug-info Differential Revision: https://reviews.llvm.org/D60831 > llvm-svn: 363046 llvm-svn: 363786 --- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 8 +- .../Transforms/Vectorize/LoopVectorize.cpp | 20 ++- .../DebugInfo/AArch64/inlined-argument.ll | 149 +++++++++--------- .../LoopIdiom/bcmp-debugify-remarks.ll | 52 +++--- .../LoopIdiom/memset-debugify-remarks.ll | 16 +- llvm/test/Transforms/LoopSimplify/dbg-loc.ll | 2 +- .../LoopSimplify/do-preheader-dbg.ll | 122 ++++++++++++++ .../LoopSimplify/for-preheader-dbg.ll | 102 ++++++++++++ .../Transforms/LoopUnroll/runtime-loop1.ll | 16 +- .../X86/vectorization-remarks-missed.ll | 12 +- .../X86/vectorization-remarks-profitable.ll | 4 +- .../test/Transforms/LoopVectorize/debugloc.ll | 9 +- .../LoopVectorize/fix-reduction-dbg.ll | 87 ++++++++++ .../LoopVectorize/unsafe-dep-remark.ll | 2 +- 14 files changed, 465 insertions(+), 136 deletions(-) create mode 100755 llvm/test/Transforms/LoopSimplify/do-preheader-dbg.ll create mode 100755 llvm/test/Transforms/LoopSimplify/for-preheader-dbg.ll create mode 100755 llvm/test/Transforms/LoopVectorize/fix-reduction-dbg.ll diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index aa69a8d00883..5fa371377c85 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -579,7 +579,13 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, // The new block unconditionally branches to the old block. BranchInst *BI = BranchInst::Create(BB, NewBB); - BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); + // Splitting the predecessors of a loop header creates a preheader block. + if (LI && LI->isLoopHeader(BB)) + // Using the loop start line number prevents debuggers stepping into the + // loop body for this instruction. + BI->setDebugLoc(LI->getLoopFor(BB)->getStartLoc()); + else + BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); // Move the edges from Preds to point to NewBB instead of BB. for (unsigned i = 0, e = Preds.size(); i != e; ++i) { diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 7b3b9ddfad4d..c1bb43bc5bdb 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2909,11 +2909,11 @@ BasicBlock *InnerLoopVectorizer::createVectorizedLoopSkeleton() { CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, Count, CountRoundDown, "cmp.n", MiddleBlock->getTerminator()); - // Provide correct stepping behaviour by using the same DebugLoc as the - // scalar loop latch branch cmp if it exists. - if (CmpInst *ScalarLatchCmp = - dyn_cast_or_null(ScalarLatchBr->getCondition())) - cast(CmpN)->setDebugLoc(ScalarLatchCmp->getDebugLoc()); + // Here we use the same DebugLoc as the scalar loop latch branch instead + // of the corresponding compare because they may have ended up with + // different line numbers and we want to avoid awkward line stepping while + // debugging. Eg. if the compare has got a line number inside the loop. + cast(CmpN)->setDebugLoc(ScalarLatchBr->getDebugLoc()); } BranchInst *BrInst = BranchInst::Create(ExitBlock, ScalarPH, CmpN); @@ -3606,7 +3606,15 @@ void InnerLoopVectorizer::fixReduction(PHINode *Phi) { // Reduce all of the unrolled parts into a single vector. Value *ReducedPartRdx = VectorLoopValueMap.getVectorValue(LoopExitInst, 0); unsigned Op = RecurrenceDescriptor::getRecurrenceBinOp(RK); - setDebugLocFromInst(Builder, ReducedPartRdx); + + // The middle block terminator has already been assigned a DebugLoc here (the + // OrigLoop's single latch terminator). We want the whole middle block to + // appear to execute on this line because: (a) it is all compiler generated, + // (b) these instructions are always executed after evaluating the latch + // conditional branch, and (c) other passes may add new predecessors which + // terminate on this line. This is the easiest way to ensure we don't + // accidentally cause an extra step back into the loop while debugging. + setDebugLocFromInst(Builder, LoopMiddleBlock->getTerminator()); for (unsigned Part = 1; Part < UF; ++Part) { Value *RdxPart = VectorLoopValueMap.getVectorValue(LoopExitInst, Part); if (Op != Instruction::ICmp && Op != Instruction::FCmp) diff --git a/llvm/test/DebugInfo/AArch64/inlined-argument.ll b/llvm/test/DebugInfo/AArch64/inlined-argument.ll index 172df98acdea..747d6d787aef 100644 --- a/llvm/test/DebugInfo/AArch64/inlined-argument.ll +++ b/llvm/test/DebugInfo/AArch64/inlined-argument.ll @@ -38,66 +38,59 @@ ; if (__builtin_expect(enable, 0)) { } ; } - -source_filename = "test.i" +; ModuleID = 'inlined-arg.c' +source_filename = "inlined-arg.c" target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" target triple = "arm64-apple-ios5.0.0" %struct.t = type { %struct.q* } %struct.q = type { %struct.q*, i64 } -@tt = local_unnamed_addr global %struct.t* null, align 8, !dbg !0 +@tt = common local_unnamed_addr global %struct.t* null, align 8, !dbg !0 -; Function Attrs: noredzone nounwind readonly ssp -define i32 @g(%struct.t* nocapture readonly %t, i64 %r) local_unnamed_addr #0 !dbg !20 { +; Function Attrs: norecurse nounwind readonly ssp uwtable +define i32 @g(%struct.t* nocapture readonly %t, i64 %r) local_unnamed_addr !dbg !21 { entry: - tail call void @llvm.dbg.value(metadata %struct.t* %t, metadata !26, metadata !DIExpression()), !dbg !29 - tail call void @llvm.dbg.value(metadata i64 %r, metadata !27, metadata !DIExpression()), !dbg !30 - tail call void @llvm.dbg.value(metadata %struct.t* %t, metadata !31, metadata !DIExpression()), !dbg !39 - tail call void @llvm.dbg.value(metadata i64 %r, metadata !37, metadata !DIExpression()), !dbg !41 - %s.i5 = bitcast %struct.t* %t to %struct.q** - tail call void @llvm.dbg.value(metadata %struct.q** %s.i5, metadata !38, metadata !DIExpression(DW_OP_deref)), !dbg !42 - %q.06.i = load %struct.q*, %struct.q** %s.i5, align 8 - tail call void @llvm.dbg.value(metadata %struct.q* %q.06.i, metadata !38, metadata !DIExpression()), !dbg !42 - %tobool7.i = icmp eq %struct.q* %q.06.i, null, !dbg !43 - br i1 %tobool7.i, label %find.exit, label %while.body.i.preheader, !dbg !43 - -while.body.i.preheader: ; preds = %entry - br label %while.body.i, !dbg !44 + call void @llvm.dbg.value(metadata %struct.t* %t, metadata !27, metadata !DIExpression()), !dbg !30 + call void @llvm.dbg.value(metadata i64 %r, metadata !28, metadata !DIExpression()), !dbg !31 + call void @llvm.dbg.value(metadata %struct.t* %t, metadata !32, metadata !DIExpression()), !dbg !39 + call void @llvm.dbg.value(metadata i64 %r, metadata !37, metadata !DIExpression()), !dbg !41 + %s.i = getelementptr inbounds %struct.t, %struct.t* %t, i64 0, i32 0, !dbg !42 + %q.05.i = load %struct.q*, %struct.q** %s.i, align 8, !dbg !43, !tbaa !44 + call void @llvm.dbg.value(metadata %struct.q* %q.05.i, metadata !38, metadata !DIExpression()), !dbg !48 + %tobool6.i = icmp eq %struct.q* %q.05.i, null, !dbg !49 + br i1 %tobool6.i, label %find.exit, label %while.body.i, !dbg !49 -while.body.i: ; preds = %while.body.i.preheader, %if.end.i - %q.08.i = phi %struct.q* [ %q.0.i, %if.end.i ], [ %q.06.i, %while.body.i.preheader ] - %resource1.i = getelementptr inbounds %struct.q, %struct.q* %q.08.i, i64 0, i32 1, !dbg !44 - %0 = load i64, i64* %resource1.i, align 8, !dbg !44 - %cmp.i = icmp eq i64 %0, %r, !dbg !47 - br i1 %cmp.i, label %find.exit, label %if.end.i, !dbg !48 +while.body.i: ; preds = %entry, %if.end.i + %q.07.i = phi %struct.q* [ %q.0.i, %if.end.i ], [ %q.05.i, %entry ] + %resource1.i = getelementptr inbounds %struct.q, %struct.q* %q.07.i, i64 0, i32 1, !dbg !50 + %0 = load i64, i64* %resource1.i, align 8, !dbg !50, !tbaa !53 + %cmp.i = icmp eq i64 %0, %r, !dbg !56 + br i1 %cmp.i, label %find.exit, label %if.end.i, !dbg !57 if.end.i: ; preds = %while.body.i - %next.i6 = bitcast %struct.q* %q.08.i to %struct.q** - tail call void @llvm.dbg.value(metadata %struct.q** %next.i6, metadata !38, metadata !DIExpression(DW_OP_deref)), !dbg !42 - %q.0.i = load %struct.q*, %struct.q** %next.i6, align 8 - tail call void @llvm.dbg.value(metadata %struct.q* %q.0.i, metadata !38, metadata !DIExpression()), !dbg !42 - %tobool.i = icmp eq %struct.q* %q.0.i, null, !dbg !43 - br i1 %tobool.i, label %find.exit, label %while.body.i, !dbg !43, !llvm.loop !49 + %next.i = getelementptr inbounds %struct.q, %struct.q* %q.07.i, i64 0, i32 0, !dbg !58 + %q.0.i = load %struct.q*, %struct.q** %next.i, align 8, !dbg !43, !tbaa !44 + call void @llvm.dbg.value(metadata %struct.q* %q.0.i, metadata !38, metadata !DIExpression()), !dbg !48 + %tobool.i = icmp eq %struct.q* %q.0.i, null, !dbg !49 + br i1 %tobool.i, label %find.exit, label %while.body.i, !dbg !49, !llvm.loop !59 find.exit: ; preds = %while.body.i, %if.end.i, %entry - ret i32 undef, !dbg !52 + call void @llvm.dbg.value(metadata %struct.q* undef, metadata !29, metadata !DIExpression()), !dbg !61 + ret i32 undef, !dbg !62 } ; Function Attrs: nounwind readnone speculatable -declare void @llvm.dbg.value(metadata, metadata, metadata) #1 - -attributes #0 = { noredzone nounwind readonly ssp } -attributes #1 = { nounwind readnone speculatable } +declare void @llvm.dbg.value(metadata, metadata, metadata) !llvm.dbg.cu = !{!2} -!llvm.module.flags = !{!16, !17, !18} -!llvm.ident = !{!19} +!llvm.module.flags = !{!16, !17, !18, !19} +!llvm.ident = !{!20} !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "tt", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true) -!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 (trunk 317516) (llvm/trunk 317518)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) -!3 = !DIFile(filename: "test.i", directory: "/") +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git cd3671d5dabc8848619d872f994770167a44ac5a)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: GNU) +!3 = !DIFile(filename: "inlined-arg.c", directory: "") !4 = !{} !5 = !{!0} !6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) @@ -113,37 +106,47 @@ attributes #1 = { nounwind readnone speculatable } !16 = !{i32 2, !"Dwarf Version", i32 2} !17 = !{i32 2, !"Debug Info Version", i32 3} !18 = !{i32 1, !"wchar_size", i32 4} -!19 = !{!"clang version 6.0.0 (trunk 317516) (llvm/trunk 317518)"} -!20 = distinct !DISubprogram(name: "g", scope: !3, file: !3, line: 18, type: !21, isLocal: false, isDefinition: true, scopeLine: 18, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !25) -!21 = !DISubroutineType(types: !22) -!22 = !{!23, !24, !15} -!23 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -!24 = !DIDerivedType(tag: DW_TAG_typedef, name: "t_t", file: !3, line: 1, baseType: !6) -!25 = !{!26, !27, !28} -!26 = !DILocalVariable(name: "t", arg: 1, scope: !20, file: !3, line: 18, type: !24) -!27 = !DILocalVariable(name: "r", arg: 2, scope: !20, file: !3, line: 18, type: !15) -!28 = !DILocalVariable(name: "q", scope: !20, file: !3, line: 19, type: !10) -!29 = !DILocation(line: 18, column: 11, scope: !20) -!30 = !DILocation(line: 18, column: 33, scope: !20) -!31 = !DILocalVariable(name: "t", arg: 1, scope: !32, file: !3, line: 9, type: !24) -!32 = distinct !DISubprogram(name: "find", scope: !3, file: !3, line: 9, type: !33, isLocal: true, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !36) -!33 = !DISubroutineType(types: !34) -!34 = !{!35, !24, !15} -!35 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned) -!36 = !{!31, !37, !38} -!37 = !DILocalVariable(name: "resource", arg: 2, scope: !32, file: !3, line: 9, type: !15) -!38 = !DILocalVariable(name: "q", scope: !32, file: !3, line: 10, type: !10) -!39 = !DILocation(line: 9, column: 31, scope: !32, inlinedAt: !40) -!40 = distinct !DILocation(line: 20, column: 7, scope: !20) -!41 = !DILocation(line: 9, column: 53, scope: !32, inlinedAt: !40) -!42 = !DILocation(line: 10, column: 13, scope: !32, inlinedAt: !40) -!43 = !DILocation(line: 12, column: 3, scope: !32, inlinedAt: !40) -!44 = !DILocation(line: 13, column: 12, scope: !45, inlinedAt: !40) -!45 = distinct !DILexicalBlock(scope: !46, file: !3, line: 13, column: 9) -!46 = distinct !DILexicalBlock(scope: !32, file: !3, line: 12, column: 13) -!47 = !DILocation(line: 13, column: 21, scope: !45, inlinedAt: !40) -!48 = !DILocation(line: 13, column: 9, scope: !46, inlinedAt: !40) -!49 = distinct !{!49, !50, !51} -!50 = !DILocation(line: 12, column: 3, scope: !32) -!51 = !DILocation(line: 16, column: 3, scope: !32) -!52 = !DILocation(line: 24, column: 1, scope: !20) +!19 = !{i32 7, !"PIC Level", i32 2} +!20 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git cd3671d5dabc8848619d872f994770167a44ac5a)"} +!21 = distinct !DISubprogram(name: "g", scope: !3, file: !3, line: 19, type: !22, scopeLine: 19, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !26) +!22 = !DISubroutineType(types: !23) +!23 = !{!24, !25, !15} +!24 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!25 = !DIDerivedType(tag: DW_TAG_typedef, name: "t_t", file: !3, line: 1, baseType: !6) +!26 = !{!27, !28, !29} +!27 = !DILocalVariable(name: "t", arg: 1, scope: !21, file: !3, line: 19, type: !25) +!28 = !DILocalVariable(name: "r", arg: 2, scope: !21, file: !3, line: 19, type: !15) +!29 = !DILocalVariable(name: "q", scope: !21, file: !3, line: 20, type: !10) +!30 = !DILocation(line: 19, column: 11, scope: !21) +!31 = !DILocation(line: 19, column: 33, scope: !21) +!32 = !DILocalVariable(name: "t", arg: 1, scope: !33, file: !3, line: 10, type: !25) +!33 = distinct !DISubprogram(name: "find", scope: !3, file: !3, line: 10, type: !34, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !36) +!34 = !DISubroutineType(types: !35) +!35 = !{!10, !25, !15} +!36 = !{!32, !37, !38} +!37 = !DILocalVariable(name: "resource", arg: 2, scope: !33, file: !3, line: 10, type: !15) +!38 = !DILocalVariable(name: "q", scope: !33, file: !3, line: 11, type: !10) +!39 = !DILocation(line: 10, column: 27, scope: !33, inlinedAt: !40) +!40 = distinct !DILocation(line: 21, column: 7, scope: !21) +!41 = !DILocation(line: 10, column: 49, scope: !33, inlinedAt: !40) +!42 = !DILocation(line: 12, column: 10, scope: !33, inlinedAt: !40) +!43 = !DILocation(line: 0, scope: !33, inlinedAt: !40) +!44 = !{!45, !45, i64 0} +!45 = !{!"any pointer", !46, i64 0} +!46 = !{!"omnipotent char", !47, i64 0} +!47 = !{!"Simple C/C++ TBAA"} +!48 = !DILocation(line: 11, column: 13, scope: !33, inlinedAt: !40) +!49 = !DILocation(line: 13, column: 3, scope: !33, inlinedAt: !40) +!50 = !DILocation(line: 14, column: 12, scope: !51, inlinedAt: !40) +!51 = distinct !DILexicalBlock(scope: !52, file: !3, line: 14, column: 9) +!52 = distinct !DILexicalBlock(scope: !33, file: !3, line: 13, column: 13) +!53 = !{!54, !55, i64 8} +!54 = !{!"q", !45, i64 0, !55, i64 8} +!55 = !{!"long long", !46, i64 0} +!56 = !DILocation(line: 14, column: 21, scope: !51, inlinedAt: !40) +!57 = !DILocation(line: 14, column: 9, scope: !52, inlinedAt: !40) +!58 = !DILocation(line: 16, column: 12, scope: !52, inlinedAt: !40) +!59 = distinct !{!59, !49, !60} +!60 = !DILocation(line: 17, column: 3, scope: !33, inlinedAt: !40) +!61 = !DILocation(line: 20, column: 13, scope: !21) +!62 = !DILocation(line: 24, column: 1, scope: !21) diff --git a/llvm/test/Transforms/LoopIdiom/bcmp-debugify-remarks.ll b/llvm/test/Transforms/LoopIdiom/bcmp-debugify-remarks.ll index b3bab51b7ee3..f21def9ec0c2 100644 --- a/llvm/test/Transforms/LoopIdiom/bcmp-debugify-remarks.ll +++ b/llvm/test/Transforms/LoopIdiom/bcmp-debugify-remarks.ll @@ -40,19 +40,19 @@ define i1 @_Z43index_iteration_eq_variable_size_no_overlapPKcm(i8* nocapture %pt ; CHECK: for.body: ; CHECK-NEXT: [[I_015:%.*]] = phi i64 [ [[INC]], [[FOR_COND:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ], !dbg !28 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[I_015]], metadata !14, metadata !DIExpression()), !dbg !28 -; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, i8* [[PTR]], i64 [[I_015]], !dbg !25 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ARRAYIDX]], metadata !15, metadata !DIExpression()), !dbg !25 -; CHECK-NEXT: [[V0:%.*]] = load i8, i8* [[ARRAYIDX]], !dbg !29 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8 [[V0]], metadata !16, metadata !DIExpression()), !dbg !29 -; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i8, i8* [[ADD_PTR]], i64 [[I_015]], !dbg !30 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ARRAYIDX1]], metadata !17, metadata !DIExpression()), !dbg !30 -; CHECK-NEXT: [[V1:%.*]] = load i8, i8* [[ARRAYIDX1]], !dbg !31 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8 [[V1]], metadata !18, metadata !DIExpression()), !dbg !31 -; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i8 [[V0]], [[V1]], !dbg !32 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP3]], metadata !19, metadata !DIExpression()), !dbg !32 -; CHECK-NEXT: [[INC]] = add nuw i64 [[I_015]], 1, !dbg !33 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[INC]], metadata !20, metadata !DIExpression()), !dbg !33 -; CHECK-NEXT: br i1 [[CMP3]], label [[FOR_COND]], label [[CLEANUP_LOOPEXIT]], !dbg !34 +; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, i8* [[PTR]], i64 [[I_015]], !dbg !29 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ARRAYIDX]], metadata !15, metadata !DIExpression()), !dbg !29 +; CHECK-NEXT: [[V0:%.*]] = load i8, i8* [[ARRAYIDX]], !dbg !30 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8 [[V0]], metadata !16, metadata !DIExpression()), !dbg !30 +; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i8, i8* [[ADD_PTR]], i64 [[I_015]], !dbg !31 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ARRAYIDX1]], metadata !17, metadata !DIExpression()), !dbg !31 +; CHECK-NEXT: [[V1:%.*]] = load i8, i8* [[ARRAYIDX1]], !dbg !32 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8 [[V1]], metadata !18, metadata !DIExpression()), !dbg !32 +; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i8 [[V0]], [[V1]], !dbg !33 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP3]], metadata !19, metadata !DIExpression()), !dbg !33 +; CHECK-NEXT: [[INC]] = add nuw i64 [[I_015]], 1, !dbg !34 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[INC]], metadata !20, metadata !DIExpression()), !dbg !34 +; CHECK-NEXT: br i1 [[CMP3]], label [[FOR_COND]], label [[CLEANUP_LOOPEXIT]], !dbg !25 ; CHECK: cleanup.loopexit: ; CHECK-NEXT: [[RES_PH:%.*]] = phi i1 [ false, [[FOR_BODY]] ], [ true, [[FOR_COND]] ] ; CHECK-NEXT: br label [[CLEANUP]], !dbg !35 @@ -100,19 +100,19 @@ define void @_Z16loop_within_loopmPPKcS1_Pm(i64 %outer_count, i8** %ptr0, i8** % ; CHECK: for.body: ; CHECK-NEXT: [[I_012:%.*]] = phi i64 [ [[INC:%.*]], [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ], !dbg !64 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[I_012]], metadata !40, metadata !DIExpression()), !dbg !64 -; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8*, i8** [[PTR0:%.*]], i64 [[I_012]], !dbg !62 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8** [[ARRAYIDX]], metadata !41, metadata !DIExpression()), !dbg !62 -; CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[ARRAYIDX]], !dbg !65 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[T0]], metadata !42, metadata !DIExpression()), !dbg !65 -; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, i64* [[COUNT:%.*]], i64 [[I_012]], !dbg !66 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i64* [[ARRAYIDX2]], metadata !43, metadata !DIExpression()), !dbg !66 -; CHECK-NEXT: [[T1:%.*]] = load i64, i64* [[ARRAYIDX2]], !dbg !67 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[T1]], metadata !44, metadata !DIExpression()), !dbg !67 -; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[T0]], i64 [[T1]], !dbg !68 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ADD_PTR]], metadata !45, metadata !DIExpression()), !dbg !68 -; CHECK-NEXT: [[CMP5_I_I:%.*]] = icmp eq i64 [[T1]], 0, !dbg !69 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP5_I_I]], metadata !46, metadata !DIExpression()), !dbg !69 -; CHECK-NEXT: br i1 [[CMP5_I_I]], label [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT]], label [[FOR_BODY_I_I_PREHEADER:%.*]], !dbg !70 +; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8*, i8** [[PTR0:%.*]], i64 [[I_012]], !dbg !65 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8** [[ARRAYIDX]], metadata !41, metadata !DIExpression()), !dbg !65 +; CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[ARRAYIDX]], !dbg !66 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[T0]], metadata !42, metadata !DIExpression()), !dbg !66 +; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, i64* [[COUNT:%.*]], i64 [[I_012]], !dbg !67 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i64* [[ARRAYIDX2]], metadata !43, metadata !DIExpression()), !dbg !67 +; CHECK-NEXT: [[T1:%.*]] = load i64, i64* [[ARRAYIDX2]], !dbg !68 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[T1]], metadata !44, metadata !DIExpression()), !dbg !68 +; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[T0]], i64 [[T1]], !dbg !69 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ADD_PTR]], metadata !45, metadata !DIExpression()), !dbg !69 +; CHECK-NEXT: [[CMP5_I_I:%.*]] = icmp eq i64 [[T1]], 0, !dbg !70 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP5_I_I]], metadata !46, metadata !DIExpression()), !dbg !70 +; CHECK-NEXT: br i1 [[CMP5_I_I]], label [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT]], label [[FOR_BODY_I_I_PREHEADER:%.*]], !dbg !62 ; CHECK: for.body.i.i.preheader: ; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i8*, i8** [[PTR1:%.*]], i64 [[I_012]], !dbg !71 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8** [[ARRAYIDX3]], metadata !47, metadata !DIExpression()), !dbg !71 diff --git a/llvm/test/Transforms/LoopIdiom/memset-debugify-remarks.ll b/llvm/test/Transforms/LoopIdiom/memset-debugify-remarks.ll index 54b39e945170..cfd1075d4d7b 100644 --- a/llvm/test/Transforms/LoopIdiom/memset-debugify-remarks.ll +++ b/llvm/test/Transforms/LoopIdiom/memset-debugify-remarks.ll @@ -24,16 +24,16 @@ define void @_Z15my_basic_memsetPcS_c(i8* %ptr, i8* %end, i8 %value) { ; CHECK-NEXT: [[TMP0:%.*]] = sub i64 0, [[PTR1]], !dbg !17 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* [[END]], i64 [[TMP0]], !dbg !17 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = ptrtoint i8* [[SCEVGEP]] to i64 -; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[PTR]], i8 [[VALUE:%.*]], i64 [[SCEVGEP2]], i1 false), !dbg !17 +; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[PTR]], i8 [[VALUE:%.*]], i64 [[SCEVGEP2]], i1 false), !dbg !18 ; CHECK-NEXT: br label [[FOR_BODY:%.*]], !dbg !17 ; CHECK: for.body: -; CHECK-NEXT: [[PTR_ADDR_04:%.*]] = phi i8* [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ], [ [[PTR]], [[FOR_BODY_PREHEADER]] ], !dbg !18 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[PTR_ADDR_04]], metadata !11, metadata !DIExpression()), !dbg !18 -; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, i8* [[PTR_ADDR_04]], i64 1, !dbg !19 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[INCDEC_PTR]], metadata !13, metadata !DIExpression()), !dbg !19 -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[INCDEC_PTR]], [[END]], !dbg !20 -; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP]], metadata !14, metadata !DIExpression()), !dbg !20 -; CHECK-NEXT: br i1 [[CMP]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]], !dbg !21 +; CHECK-NEXT: [[PTR_ADDR_04:%.*]] = phi i8* [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ], [ [[PTR]], [[FOR_BODY_PREHEADER]] ], !dbg !19 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[PTR_ADDR_04]], metadata !11, metadata !DIExpression()), !dbg !19 +; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, i8* [[PTR_ADDR_04]], i64 1, !dbg !20 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[INCDEC_PTR]], metadata !13, metadata !DIExpression()), !dbg !20 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[INCDEC_PTR]], [[END]], !dbg !21 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP]], metadata !14, metadata !DIExpression()), !dbg !21 +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]], !dbg !17 ; CHECK: for.end.loopexit: ; CHECK-NEXT: br label [[FOR_END]], !dbg !22 ; CHECK: for.end: diff --git a/llvm/test/Transforms/LoopSimplify/dbg-loc.ll b/llvm/test/Transforms/LoopSimplify/dbg-loc.ll index efd5e8e71c92..4bc519338cbf 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 000000000000..7cacc49cd80a --- /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> , !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> , !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> , !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> , !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 000000000000..439b72024c3c --- /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) diff --git a/llvm/test/Transforms/LoopUnroll/runtime-loop1.ll b/llvm/test/Transforms/LoopUnroll/runtime-loop1.ll index fb42443f326b..7e4866ced4ba 100644 --- a/llvm/test/Transforms/LoopUnroll/runtime-loop1.ll +++ b/llvm/test/Transforms/LoopUnroll/runtime-loop1.ll @@ -10,31 +10,29 @@ ; EPILOG: for.body.preheader: ; EPILOG: br i1 %1, label %for.end.loopexit.unr-lcssa, label %for.body.preheader.new, !dbg [[PH_LOC:![0-9]+]] ; EPILOG: for.body: -; EPILOG: br i1 %niter.ncmp.1, label %for.end.loopexit.unr-lcssa.loopexit, label %for.body, !dbg [[BODY_LOC:![0-9]+]] +; EPILOG: br i1 %niter.ncmp.1, label %for.end.loopexit.unr-lcssa.loopexit, label %for.body, !dbg [[PH_LOC]] ; EPILOG-NOT: br i1 %niter.ncmp.2, label %for.end.loopexit{{.*}}, label %for.body ; EPILOG: for.body.epil.preheader: -; EPILOG: br label %for.body.epil, !dbg [[BODY_LOC]] +; EPILOG: br label %for.body.epil, !dbg [[PH_LOC]] ; EPILOG: for.body.epil: -; EPILOG: br label %for.end.loopexit.epilog-lcssa, !dbg [[BODY_LOC]] +; EPILOG: br label %for.end.loopexit.epilog-lcssa, !dbg [[PH_LOC]] ; EPILOG: for.end.loopexit: ; EPILOG: br label %for.end, !dbg [[EXIT_LOC:![0-9]+]] -; EPILOG-DAG: [[PH_LOC]] = !DILocation(line: 101, column: 1, scope: !{{.*}}) -; EPILOG-DAG: [[BODY_LOC]] = !DILocation(line: 102, column: 1, scope: !{{.*}}) +; EPILOG-DAG: [[PH_LOC]] = !DILocation(line: 102, column: 1, scope: !{{.*}}) ; EPILOG-DAG: [[EXIT_LOC]] = !DILocation(line: 103, column: 1, scope: !{{.*}}) ; PROLOG: for.body.preheader: ; PROLOG: br {{.*}} label %for.body.prol.preheader, label %for.body.prol.loopexit, !dbg [[PH_LOC:![0-9]+]] ; PROLOG: for.body.prol: -; PROLOG: br label %for.body.prol.loopexit, !dbg [[BODY_LOC:![0-9]+]] +; PROLOG: br label %for.body.prol.loopexit, !dbg [[PH_LOC:![0-9]+]] ; PROLOG: for.body.prol.loopexit: ; PROLOG: br {{.*}} label %for.end.loopexit, label %for.body.preheader.new, !dbg [[PH_LOC]] ; PROLOG: for.body: -; PROLOG: br i1 %exitcond.1, label %for.end.loopexit.unr-lcssa, label %for.body, !dbg [[BODY_LOC]] +; PROLOG: br i1 %exitcond.1, label %for.end.loopexit.unr-lcssa, label %for.body, !dbg [[PH_LOC]] ; PROLOG-NOT: br i1 %exitcond.4, label %for.end.loopexit{{.*}}, label %for.body -; PROLOG-DAG: [[PH_LOC]] = !DILocation(line: 101, column: 1, scope: !{{.*}}) -; PROLOG-DAG: [[BODY_LOC]] = !DILocation(line: 102, column: 1, scope: !{{.*}}) +; PROLOG-DAG: [[PH_LOC]] = !DILocation(line: 102, column: 1, scope: !{{.*}}) define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly !dbg !6 { entry: diff --git a/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll b/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll index 4aa96df94fff..a90ce99268b3 100644 --- a/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll @@ -16,15 +16,15 @@ ; } ; } ; File, line, and column should match those specified in the metadata -; CHECK: remark: source.cpp:4:5: loop not vectorized: could not determine number of loop iterations -; CHECK: remark: source.cpp:4:5: loop not vectorized +; CHECK: remark: source.cpp:5:9: loop not vectorized: could not determine number of loop iterations +; CHECK: remark: source.cpp:5:9: loop not vectorized ; void test_disabled(int *A, int Length) { ; #pragma clang loop vectorize(disable) interleave(disable) ; for (int i = 0; i < Length; i++) ; A[i] = i; ; } -; CHECK: remark: source.cpp:13:5: loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized +; CHECK: remark: source.cpp:12:8: loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized ; void test_array_bounds(int *A, int *B, int Length) { ; #pragma clang loop vectorize(enable) @@ -51,7 +51,7 @@ ; YAML: --- !Analysis ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: CantComputeNumberOfIterations -; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 4, Column: 5 } +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 } ; YAML-NEXT: Function: _Z4testPii ; YAML-NEXT: Args: ; YAML-NEXT: - String: 'loop not vectorized: ' @@ -60,7 +60,7 @@ ; YAML-NEXT: --- !Missed ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: MissedDetails -; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 4, Column: 5 } +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 } ; YAML-NEXT: Function: _Z4testPii ; YAML-NEXT: Args: ; YAML-NEXT: - String: loop not vectorized @@ -68,7 +68,7 @@ ; YAML-NEXT: --- !Analysis ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: AllDisabled -; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 13, Column: 5 } +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 12, Column: 8 } ; YAML-NEXT: Function: _Z13test_disabledPii ; YAML-NEXT: Args: ; YAML-NEXT: - String: 'loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized diff --git a/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-profitable.ll b/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-profitable.ll index ac0648a68389..228515efc701 100644 --- a/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-profitable.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-profitable.ll @@ -3,8 +3,8 @@ ; Verify analysis remarks are generated when interleaving is not beneficial. ; CHECK: remark: vectorization-remarks-profitable.c:5:17: the cost-model indicates that vectorization is not beneficial ; CHECK: remark: vectorization-remarks-profitable.c:5:17: the cost-model indicates that interleaving is not beneficial and is explicitly disabled or interleave count is set to 1 -; CHECK: remark: vectorization-remarks-profitable.c:12:17: the cost-model indicates that vectorization is not beneficial -; CHECK: remark: vectorization-remarks-profitable.c:12:17: the cost-model indicates that interleaving is not beneficial +; CHECK: remark: vectorization-remarks-profitable.c:11:3: the cost-model indicates that vectorization is not beneficial +; CHECK: remark: vectorization-remarks-profitable.c:11:3: the cost-model indicates that interleaving is not beneficial ; First loop. ; #pragma clang loop interleave(disable) unroll(disable) diff --git a/llvm/test/Transforms/LoopVectorize/debugloc.ll b/llvm/test/Transforms/LoopVectorize/debugloc.ll index e9ec8662ce46..358f49b99269 100644 --- a/llvm/test/Transforms/LoopVectorize/debugloc.ll +++ b/llvm/test/Transforms/LoopVectorize/debugloc.ll @@ -14,8 +14,11 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3 ; CHECK: add i64 %index, 2, !dbg ![[LOC]] ; CHECK: icmp eq i64 %index.next, %n.vec, !dbg ![[LOC]] ; CHECK: middle.block -; CHECK: add <2 x i32> %{{.*}}, %rdx.shuf, !dbg ![[LOC]] -; CHECK: extractelement <2 x i32> %bin.rdx, i32 0, !dbg ![[LOC]] +; CHECK: add <2 x i32> %{{.*}}, %rdx.shuf, !dbg ![[BR_LOC:[0-9]+]] +; CHECK: extractelement <2 x i32> %bin.rdx, i32 0, !dbg ![[BR_LOC]] +; CHECK: for.body +; CHECK br i1{{.*}}, label %for.body,{{.*}}, !dbg ![[BR_LOC]], +; CHECK: ![[BR_LOC]] = !DILocation(line: 5, define i32 @f(i32* nocapture %a, i32 %size) #0 !dbg !4 { entry: @@ -38,7 +41,7 @@ for.body: ; preds = %for.body.lr.ph, %fo %indvars.iv.next = add i64 %indvars.iv, 1, !dbg !22 call void @llvm.dbg.value(metadata !{null}, metadata !16, metadata !DIExpression()), !dbg !22 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !22 - %exitcond = icmp ne i32 %lftr.wideiv, %size, !dbg !22 + %exitcond = icmp ne i32 %lftr.wideiv, %size, !dbg !21 br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge, !dbg !21 for.cond.for.end_crit_edge: ; preds = %for.body diff --git a/llvm/test/Transforms/LoopVectorize/fix-reduction-dbg.ll b/llvm/test/Transforms/LoopVectorize/fix-reduction-dbg.ll new file mode 100755 index 000000000000..457bdacc35a1 --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/fix-reduction-dbg.ll @@ -0,0 +1,87 @@ +; Confirm that the line numbers for the middle.block operations are all the +; same as the start of the loop. + +; RUN: opt -S -loop-vectorize -force-vector-width=4 -force-vector-interleave=4 <%s | FileCheck %s +; +; CHECK: middle.block: +; CHECK-NEXT: %{{.*}}= add <4 x i32>{{.*}}, !dbg ![[DL:[0-9]+]] +; CHECK-NEXT: %{{.*}}= add <4 x i32>{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: %{{.*}}= add <4 x i32>{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: %{{.*}}= shufflevector <4 x i32>{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: %{{.*}}= add <4 x i32>{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: %{{.*}}= shufflevector <4 x i32>{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: %{{.*}}= add <4 x i32>{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: %{{.*}}= extractelement <4 x i32>{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: %{{.*}}= icmp eq i64{{.*}}, !dbg ![[DL]] +; CHECK-NEXT: br i1 %{{.*}}, !dbg ![[DL]] +; CHECK: ![[DL]] = !DILocation(line: 5, + +; This IR can be generated by running: +; clang -gmlt -S src.cpp -emit-llvm -mllvm -opt-bisect-limit=56 -O2 -o - +; +; Where src.cpp contains: +; int foo(int count, int *bar) +; { +; 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: + %cmp8 = icmp sgt i32 %count, 0, !dbg !10 + br i1 %cmp8, label %for.body.preheader, label %for.cond.cleanup, !dbg !10 + +for.body.preheader: ; preds = %entry + %wide.trip.count = zext i32 %count to i64 + br label %for.body, !dbg !11 + +for.cond.cleanup.loopexit: ; preds = %for.body + %add.lcssa = phi i32 [ %add, %for.body ], !dbg !12 + br label %for.cond.cleanup, !dbg !13 + +for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry + %ret.0.lcssa = phi i32 [ %count, %entry ], [ %add.lcssa, %for.cond.cleanup.loopexit ], !dbg !14 + ret i32 %ret.0.lcssa, !dbg !13 + +for.body: ; preds = %for.body, %for.body.preheader + %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] + %ret.09 = phi i32 [ %count, %for.body.preheader ], [ %add, %for.body ] + %arrayidx = getelementptr inbounds i32, i32* %bar, i64 %indvars.iv, !dbg !11 + %0 = load i32, i32* %arrayidx, align 4, !dbg !11, !tbaa !15 + %add = add nsw i32 %0, %ret.09, !dbg !12 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !10 + %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count, !dbg !10 + br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body, !dbg !10, !llvm.loop !19 +} + +!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: "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", 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: 5, scope: !8) +!11 = !DILocation(line: 6, scope: !8) +!12 = !DILocation(line: 7, scope: !8) +!13 = !DILocation(line: 10, scope: !8) +!14 = !DILocation(line: 0, scope: !8) +!15 = !{!16, !16, i64 0} +!16 = !{!"int", !17, i64 0} +!17 = !{!"omnipotent char", !18, i64 0} +!18 = !{!"Simple C++ TBAA"} +!19 = distinct !{!19, !10, !20} +!20 = !DILocation(line: 8, scope: !8) diff --git a/llvm/test/Transforms/LoopVectorize/unsafe-dep-remark.ll b/llvm/test/Transforms/LoopVectorize/unsafe-dep-remark.ll index 78e128d897e9..be20be538173 100644 --- a/llvm/test/Transforms/LoopVectorize/unsafe-dep-remark.ll +++ b/llvm/test/Transforms/LoopVectorize/unsafe-dep-remark.ll @@ -11,7 +11,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" ; 5 } ; 6 } -; CHECK: remark: /tmp/kk.c:3:16: loop not vectorized: unsafe dependent memory operations in loop. Use #pragma loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop +; CHECK: remark: /tmp/kk.c:2:3: loop not vectorized: unsafe dependent memory operations in loop. Use #pragma loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop define void @success(i8* nocapture %A, i8* nocapture readonly %B, i8* nocapture %C, i8* nocapture readonly %D, i8* nocapture readonly %E, i32 %N) !dbg !6 { entry: -- 2.34.1