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