160 lines · plain
1; This test checks that the !llvm.loop metadata has been updated after inlining2; so that the start and end locations refer to the inlined DILocations.3 4; RUN: opt -passes='cgscc(inline),always-inline' %s -S 2>&1 | FileCheck %s5; CHECK: br i1 %{{.*}}, label %middle.block.i, label %vector.body.i, !dbg !{{[0-9]+}}, !llvm.loop [[VECTOR:![0-9]+]]6; CHECK: br i1 %{{.*}}, label %for.cond.cleanup.loopexit.i, label %for.body.i, !dbg !{{[0-9]+}}, !llvm.loop [[SCALAR:![0-9]+]]7; CHECK-DAG: [[VECTOR]] = distinct !{[[VECTOR]], [[START:![0-9]+]], [[END:![0-9]+]], [[IS_VECTORIZED:![0-9]+]]}8; CHECK-DAG: [[SCALAR]] = distinct !{[[SCALAR]], [[START]], [[END]], [[NO_UNROLL:![0-9]+]], [[IS_VECTORIZED]]}9; CHECK-DAG: [[IS_VECTORIZED]] = !{!"llvm.loop.isvectorized", i32 1}10; CHECK-DAG: [[NO_UNROLL]] = !{!"llvm.loop.unroll.runtime.disable"}11 12; This IR can be generated by running:13; clang -emit-llvm -S -gmlt -O2 inlined.cpp -o - -mllvm -opt-bisect-limit=53 |\14; opt -loop-vectorize15;16; Where inlined.cpp contains:17; extern int *Array;18; static int bar(unsigned x)19; {20; int Ret = 0;21; for (unsigned i = 0; i < x; ++i)22; {23; Ret += Array[i] * i;24; }25; return Ret;26; }27;28; int foo(unsigned x)29; {30; int Bar = bar(x);31; return Bar;32; }33 34@"?Array@@3PEAHEA" = external dso_local local_unnamed_addr global ptr, align 835 36define dso_local i32 @"?foo@@YAHI@Z"(i32 %x) local_unnamed_addr !dbg !8 {37entry:38 %call = call fastcc i32 @"?bar@@YAHI@Z"(i32 %x), !dbg !1039 ret i32 %call, !dbg !1140}41 42define internal fastcc i32 @"?bar@@YAHI@Z"(i32 %x) unnamed_addr !dbg !12 {43entry:44 %cmp7 = icmp eq i32 %x, 0, !dbg !1345 br i1 %cmp7, label %for.cond.cleanup, label %for.body.lr.ph, !dbg !1346 47for.body.lr.ph: ; preds = %entry48 %0 = load ptr, ptr @"?Array@@3PEAHEA", align 8, !dbg !14, !tbaa !1549 %wide.trip.count = zext i32 %x to i64, !dbg !1450 %min.iters.check = icmp ult i64 %wide.trip.count, 8, !dbg !1351 br i1 %min.iters.check, label %scalar.ph, label %vector.ph, !dbg !1352 53vector.ph: ; preds = %for.body.lr.ph54 %n.mod.vf = urem i64 %wide.trip.count, 8, !dbg !1355 %n.vec = sub i64 %wide.trip.count, %n.mod.vf, !dbg !1356 br label %vector.body, !dbg !1357 58vector.body: ; preds = %vector.body, %vector.ph59 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ], !dbg !1360 %vec.ind = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]61 %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %17, %vector.body ]62 %vec.phi2 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]63 %vec.ind4 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next7, %vector.body ], !dbg !1964 %step.add = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>65 %1 = add i64 %index, 0, !dbg !1366 %2 = add i64 %index, 1, !dbg !1367 %3 = add i64 %index, 2, !dbg !1368 %4 = add i64 %index, 3, !dbg !1369 %5 = add i64 %index, 4, !dbg !1370 %6 = add i64 %index, 5, !dbg !1371 %7 = add i64 %index, 6, !dbg !1372 %8 = add i64 %index, 7, !dbg !1373 %9 = getelementptr inbounds i32, ptr %0, i64 %1, !dbg !1974 %10 = getelementptr inbounds i32, ptr %0, i64 %5, !dbg !1975 %11 = getelementptr inbounds i32, ptr %9, i32 0, !dbg !1976 %12 = bitcast ptr %11 to ptr, !dbg !1977 %wide.load = load <4 x i32>, ptr %12, align 4, !dbg !19, !tbaa !2078 %13 = getelementptr inbounds i32, ptr %9, i32 4, !dbg !1979 %14 = bitcast ptr %13 to ptr, !dbg !1980 %wide.load3 = load <4 x i32>, ptr %14, align 4, !dbg !19, !tbaa !2081 %step.add5 = add <4 x i32> %vec.ind4, <i32 4, i32 4, i32 4, i32 4>, !dbg !1982 %15 = mul <4 x i32> %wide.load, %vec.ind4, !dbg !1983 %16 = mul <4 x i32> %wide.load3, %step.add5, !dbg !1984 %17 = add <4 x i32> %15, %vec.phi, !dbg !1985 %18 = add <4 x i32> %16, %vec.phi2, !dbg !1986 %index.next = add i64 %index, 8, !dbg !1387 %vec.ind.next = add <4 x i64> %step.add, <i64 4, i64 4, i64 4, i64 4>88 %vec.ind.next7 = add <4 x i32> %step.add5, <i32 4, i32 4, i32 4, i32 4>, !dbg !1989 %19 = icmp eq i64 %index.next, %n.vec, !dbg !1390 br i1 %19, label %middle.block, label %vector.body, !dbg !13, !llvm.loop !2291 92middle.block: ; preds = %vector.body93 %bin.rdx = add <4 x i32> %18, %17, !dbg !1994 %rdx.shuf = shufflevector <4 x i32> %bin.rdx, <4 x i32> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>, !dbg !1995 %bin.rdx8 = add <4 x i32> %bin.rdx, %rdx.shuf, !dbg !1996 %rdx.shuf9 = shufflevector <4 x i32> %bin.rdx8, <4 x i32> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>, !dbg !1997 %bin.rdx10 = add <4 x i32> %bin.rdx8, %rdx.shuf9, !dbg !1998 %20 = extractelement <4 x i32> %bin.rdx10, i32 0, !dbg !1999 %cmp.n = icmp eq i64 %wide.trip.count, %n.vec, !dbg !13100 br i1 %cmp.n, label %for.cond.cleanup.loopexit, label %scalar.ph, !dbg !13101 102scalar.ph: ; preds = %middle.block, %for.body.lr.ph103 %bc.resume.val = phi i64 [ %n.vec, %middle.block ], [ 0, %for.body.lr.ph ]104 %bc.merge.rdx = phi i32 [ 0, %for.body.lr.ph ], [ %20, %middle.block ]105 br label %for.body, !dbg !13106 107for.cond.cleanup.loopexit: ; preds = %middle.block, %for.body108 %add.lcssa = phi i32 [ %add, %for.body ], [ %20, %middle.block ], !dbg !19109 br label %for.cond.cleanup, !dbg !25110 111for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry112 %Ret.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %for.cond.cleanup.loopexit ], !dbg !14113 ret i32 %Ret.0.lcssa, !dbg !25114 115for.body: ; preds = %for.body, %scalar.ph116 %indvars.iv = phi i64 [ %bc.resume.val, %scalar.ph ], [ %indvars.iv.next, %for.body ]117 %Ret.08 = phi i32 [ %bc.merge.rdx, %scalar.ph ], [ %add, %for.body ]118 %arrayidx = getelementptr inbounds i32, ptr %0, i64 %indvars.iv, !dbg !19119 %21 = load i32, ptr %arrayidx, align 4, !dbg !19, !tbaa !20120 %22 = trunc i64 %indvars.iv to i32, !dbg !19121 %mul = mul i32 %21, %22, !dbg !19122 %add = add i32 %mul, %Ret.08, !dbg !19123 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !13124 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count, !dbg !13125 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body, !dbg !13, !llvm.loop !26126}127 128!llvm.dbg.cu = !{!0}129!llvm.module.flags = !{!3, !4, !5, !6}130!llvm.ident = !{!7}131 132!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git b1e28d9b6a16380ccf1456fe0695f639364407a9)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: None)133!1 = !DIFile(filename: "inlined.cpp", directory: "")134!2 = !{}135!3 = !{i32 2, !"CodeView", i32 1}136!4 = !{i32 2, !"Debug Info Version", i32 3}137!5 = !{i32 1, !"wchar_size", i32 2}138!6 = !{i32 7, !"PIC Level", i32 2}139!7 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git b1e28d9b6a16380ccf1456fe0695f639364407a9)"}140!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 13, type: !9, scopeLine: 14, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)141!9 = !DISubroutineType(types: !2)142!10 = !DILocation(line: 15, scope: !8)143!11 = !DILocation(line: 16, scope: !8)144!12 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)145!13 = !DILocation(line: 6, scope: !12)146!14 = !DILocation(line: 0, scope: !12)147!15 = !{!16, !16, i64 0}148!16 = !{!"any pointer", !17, i64 0}149!17 = !{!"omnipotent char", !18, i64 0}150!18 = !{!"Simple C++ TBAA"}151!19 = !DILocation(line: 8, scope: !12)152!20 = !{!21, !21, i64 0}153!21 = !{!"int", !17, i64 0}154!22 = distinct !{!22, !13, !23, !24}155!23 = !DILocation(line: 9, scope: !12)156!24 = !{!"llvm.loop.isvectorized", i32 1}157!25 = !DILocation(line: 10, scope: !12)158!26 = distinct !{!26, !13, !23, !27, !24}159!27 = !{!"llvm.loop.unroll.runtime.disable"}160