1; RUN: opt < %s -debug-only=loop-vectorize -loop-vectorize -mtriple=x86_64-unknown-linux -S 2>&1 | FileCheck %s 2; REQUIRES: asserts 3 4; Test that the register usage estimation is not affected by the presence of 5; debug intrinsics. 6; 7; In the test below the values %0 and %r.08 are ended in the add instruction 8; preceding the call to the intrinsic, and will be recorded against the index 9; of the call instruction. This means the debug intrinsic must be considered 10; when erasing instructions from the list of open-intervals. 11; 12; Tests generated from following source (with and without -g): 13 14; unsigned test(unsigned *a, unsigned n) { 15; unsigned i, r = 0; 16; for(i = 0; i < n; i++) 17; r += a[i]; 18; return r; 19; } 20 21target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 22target triple = "x86_64-unknown-linux-gnu" 23 24; CHECK: LV: Checking a loop in "test_g" 25; CHECK: LV(REG): Found max usage: 2 26 27define i32 @test_g(i32* nocapture readonly %a, i32 %n) local_unnamed_addr !dbg !6 { 28entry: 29 tail call void @llvm.dbg.value(metadata i32* %a, i64 0, metadata !12, metadata !16), !dbg !17 30 tail call void @llvm.dbg.value(metadata i32 %n, i64 0, metadata !13, metadata !16), !dbg !18 31 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !15, metadata !16), !dbg !19 32 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !16), !dbg !20 33 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !15, metadata !16), !dbg !19 34 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !16), !dbg !20 35 %cmp6 = icmp eq i32 %n, 0, !dbg !21 36 br i1 %cmp6, label %for.end, label %for.body.preheader, !dbg !25 37 38for.body.preheader: ; preds = %entry 39 %wide.trip.count = zext i32 %n to i64, !dbg !21 40 br label %for.body, !dbg !27 41 42for.body: ; preds = %for.body.preheader, %for.body 43 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ] 44 %r.08 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ] 45 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv, !dbg !27 46 %0 = load i32, i32* %arrayidx, align 4, !dbg !27, !tbaa !28 47 %add = add i32 %0, %r.08, !dbg !32 48 tail call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !15, metadata !16), !dbg !19 49 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !33 50 tail call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !15, metadata !16), !dbg !19 51 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count, !dbg !21 52 br i1 %exitcond, label %for.end.loopexit, label %for.body, !dbg !25, !llvm.loop !35 53 54for.end.loopexit: ; preds = %for.body 55 br label %for.end, !dbg !38 56 57for.end: ; preds = %for.end.loopexit, %entry 58 %r.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ] 59 ret i32 %r.0.lcssa, !dbg !38 60} 61 62; CHECK: LV: Checking a loop in "test" 63; CHECK: LV(REG): Found max usage: 2 64 65define i32 @test(i32* nocapture readonly %a, i32 %n) local_unnamed_addr { 66entry: 67 %cmp6 = icmp eq i32 %n, 0 68 br i1 %cmp6, label %for.end, label %for.body.preheader 69 70for.body.preheader: ; preds = %entry 71 %wide.trip.count = zext i32 %n to i64 72 br label %for.body 73 74for.body: ; preds = %for.body.preheader, %for.body 75 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ] 76 %r.08 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ] 77 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 78 %0 = load i32, i32* %arrayidx, align 4, !tbaa !28 79 %add = add i32 %0, %r.08 80 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 81 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count 82 br i1 %exitcond, label %for.end.loopexit, label %for.body 83 84for.end.loopexit: ; preds = %for.body 85 br label %for.end 86 87for.end: ; preds = %for.end.loopexit, %entry 88 %r.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ] 89 ret i32 %r.0.lcssa 90} 91 92declare void @llvm.dbg.value(metadata, i64, metadata, metadata) 93 94!llvm.dbg.cu = !{!0} 95!llvm.module.flags = !{!3, !4} 96 97!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 98!1 = !DIFile(filename: "test.c", directory: "") 99!2 = !{} 100!3 = !{i32 2, !"Dwarf Version", i32 4} 101!4 = !{i32 2, !"Debug Info Version", i32 3} 102!6 = distinct !DISubprogram(name: "test_g", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !11) 103!7 = !DISubroutineType(types: !8) 104!8 = !{!9, !10, !9} 105!9 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 106!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) 107!11 = !{!12, !13, !14, !15} 108!12 = !DILocalVariable(name: "a", arg: 1, scope: !6, file: !1, line: 1, type: !10) 109!13 = !DILocalVariable(name: "n", arg: 2, scope: !6, file: !1, line: 1, type: !9) 110!14 = !DILocalVariable(name: "i", scope: !6, file: !1, line: 2, type: !9) 111!15 = !DILocalVariable(name: "r", scope: !6, file: !1, line: 2, type: !9) 112!16 = !DIExpression() 113!17 = !DILocation(line: 1, column: 27, scope: !6) 114!18 = !DILocation(line: 1, column: 39, scope: !6) 115!19 = !DILocation(line: 2, column: 15, scope: !6) 116!20 = !DILocation(line: 2, column: 12, scope: !6) 117!21 = !DILocation(line: 3, column: 16, scope: !22) 118!22 = !DILexicalBlockFile(scope: !23, file: !1, discriminator: 1) 119!23 = distinct !DILexicalBlock(scope: !24, file: !1, line: 3, column: 3) 120!24 = distinct !DILexicalBlock(scope: !6, file: !1, line: 3, column: 3) 121!25 = !DILocation(line: 3, column: 3, scope: !26) 122!26 = !DILexicalBlockFile(scope: !24, file: !1, discriminator: 1) 123!27 = !DILocation(line: 4, column: 10, scope: !23) 124!28 = !{!29, !29, i64 0} 125!29 = !{!"int", !30, i64 0} 126!30 = !{!"omnipotent char", !31, i64 0} 127!31 = !{!"Simple C/C++ TBAA"} 128!32 = !DILocation(line: 4, column: 7, scope: !23) 129!33 = !DILocation(line: 3, column: 22, scope: !34) 130!34 = !DILexicalBlockFile(scope: !23, file: !1, discriminator: 2) 131!35 = distinct !{!35, !36, !37} 132!36 = !DILocation(line: 3, column: 3, scope: !24) 133!37 = !DILocation(line: 4, column: 13, scope: !24) 134!38 = !DILocation(line: 5, column: 3, scope: !6) 135