143 lines · plain
1; RUN: opt < %s -debug-only=loop-vectorize,vplan -passes=loop-vectorize -mtriple=x86_64-unknown-linux -S 2>&1 | FileCheck %s2; REQUIRES: asserts3 4; Test that the register usage estimation is not affected by the presence of5; debug intrinsics.6;7; In the test below the values %0 and %r.08 are ended in the add instruction8; preceding the call to the intrinsic, and will be recorded against the index9; of the call instruction. This means the debug intrinsic must be considered10; 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 item26; CHECK-NEXT: LV(REG): RegisterClass: Generic::ScalarRC, 2 registers27; CHECK-NEXT: LV(REG): RegisterClass: Generic::VectorRC, 2 registers28; CHECK-NEXT: LV(REG): Found invariant usage: 1 item29; CHECK-NEXT: LV(REG): RegisterClass: Generic::ScalarRC, 1 registers30 31define i32 @test_g(ptr nocapture readonly %a, i32 %n) local_unnamed_addr !dbg !6 {32entry:33 tail call void @llvm.dbg.value(metadata ptr %a, i64 0, metadata !12, metadata !16), !dbg !1734 tail call void @llvm.dbg.value(metadata i32 %n, i64 0, metadata !13, metadata !16), !dbg !1835 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !15, metadata !16), !dbg !1936 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !16), !dbg !2037 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !15, metadata !16), !dbg !1938 tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !16), !dbg !2039 %cmp6 = icmp eq i32 %n, 0, !dbg !2140 br i1 %cmp6, label %for.end, label %for.body.preheader, !dbg !2541 42for.body.preheader: ; preds = %entry43 %wide.trip.count = zext i32 %n to i64, !dbg !2144 br label %for.body, !dbg !2745 46for.body: ; preds = %for.body.preheader, %for.body47 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]48 %r.08 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]49 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv, !dbg !2750 %0 = load i32, ptr %arrayidx, align 4, !dbg !27, !tbaa !2851 %add = add i32 %0, %r.08, !dbg !3252 tail call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !15, metadata !16), !dbg !1953 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !3354 tail call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !15, metadata !16), !dbg !1955 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count, !dbg !2156 br i1 %exitcond, label %for.end.loopexit, label %for.body, !dbg !25, !llvm.loop !3557 58for.end.loopexit: ; preds = %for.body59 br label %for.end, !dbg !3860 61for.end: ; preds = %for.end.loopexit, %entry62 %r.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ]63 ret i32 %r.0.lcssa, !dbg !3864}65 66; CHECK: LV: Checking a loop in 'test'67; CHECK: LV(REG): Found max usage: 2 item68; CHECK-NEXT: LV(REG): RegisterClass: Generic::ScalarRC, 2 registers69; CHECK-NEXT: LV(REG): RegisterClass: Generic::VectorRC, 2 registers70; CHECK-NEXT: LV(REG): Found invariant usage: 1 item71; CHECK-NEXT: LV(REG): RegisterClass: Generic::ScalarRC, 1 registers72 73define i32 @test(ptr nocapture readonly %a, i32 %n) local_unnamed_addr {74entry:75 %cmp6 = icmp eq i32 %n, 076 br i1 %cmp6, label %for.end, label %for.body.preheader77 78for.body.preheader: ; preds = %entry79 %wide.trip.count = zext i32 %n to i6480 br label %for.body81 82for.body: ; preds = %for.body.preheader, %for.body83 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]84 %r.08 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]85 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv86 %0 = load i32, ptr %arrayidx, align 4, !tbaa !2887 %add = add i32 %0, %r.0888 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 189 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count90 br i1 %exitcond, label %for.end.loopexit, label %for.body91 92for.end.loopexit: ; preds = %for.body93 br label %for.end94 95for.end: ; preds = %for.end.loopexit, %entry96 %r.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.end.loopexit ]97 ret i32 %r.0.lcssa98}99 100declare void @llvm.dbg.value(metadata, i64, metadata, metadata)101 102!llvm.dbg.cu = !{!0}103!llvm.module.flags = !{!3, !4}104 105!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)106!1 = !DIFile(filename: "test.c", directory: "")107!2 = !{}108!3 = !{i32 2, !"Dwarf Version", i32 4}109!4 = !{i32 2, !"Debug Info Version", i32 3}110!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)111!7 = !DISubroutineType(types: !8)112!8 = !{!9, !10, !9}113!9 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)114!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)115!11 = !{!12, !13, !14, !15}116!12 = !DILocalVariable(name: "a", arg: 1, scope: !6, file: !1, line: 1, type: !10)117!13 = !DILocalVariable(name: "n", arg: 2, scope: !6, file: !1, line: 1, type: !9)118!14 = !DILocalVariable(name: "i", scope: !6, file: !1, line: 2, type: !9)119!15 = !DILocalVariable(name: "r", scope: !6, file: !1, line: 2, type: !9)120!16 = !DIExpression()121!17 = !DILocation(line: 1, column: 27, scope: !6)122!18 = !DILocation(line: 1, column: 39, scope: !6)123!19 = !DILocation(line: 2, column: 15, scope: !6)124!20 = !DILocation(line: 2, column: 12, scope: !6)125!21 = !DILocation(line: 3, column: 16, scope: !22)126!22 = !DILexicalBlockFile(scope: !23, file: !1, discriminator: 1)127!23 = distinct !DILexicalBlock(scope: !24, file: !1, line: 3, column: 3)128!24 = distinct !DILexicalBlock(scope: !6, file: !1, line: 3, column: 3)129!25 = !DILocation(line: 3, column: 3, scope: !26)130!26 = !DILexicalBlockFile(scope: !24, file: !1, discriminator: 1)131!27 = !DILocation(line: 4, column: 10, scope: !23)132!28 = !{!29, !29, i64 0}133!29 = !{!"int", !30, i64 0}134!30 = !{!"omnipotent char", !31, i64 0}135!31 = !{!"Simple C/C++ TBAA"}136!32 = !DILocation(line: 4, column: 7, scope: !23)137!33 = !DILocation(line: 3, column: 22, scope: !34)138!34 = !DILexicalBlockFile(scope: !23, file: !1, discriminator: 2)139!35 = distinct !{!35, !36, !37}140!36 = !DILocation(line: 3, column: 3, scope: !24)141!37 = !DILocation(line: 4, column: 13, scope: !24)142!38 = !DILocation(line: 5, column: 3, scope: !6)143