1 ; RUN: opt -S -loop-rotate < %s | FileCheck --check-prefix=FULL %s
2 ; RUN: opt -S -loop-rotate -rotation-prepare-for-lto < %s | FileCheck --check-prefix=PREPARE %s
3 ; RUN: opt -S -passes='require<targetir>,require<assumptions>,loop(loop-rotate)' < %s | FileCheck --check-prefix=FULL %s
4 ; RUN: opt -S -passes='require<targetir>,require<assumptions>,loop(loop-rotate)' -rotation-prepare-for-lto < %s | FileCheck --check-prefix=PREPARE %s
6 ; Test case to make sure loop-rotate avoids rotating during the prepare-for-lto
7 ; stage, when the header contains a call which may be inlined during the LTO stage.
8 define void @test_prepare_for_lto() {
9 ; FULL-LABEL: @test_prepare_for_lto(
11 ; FULL-NEXT: %array = alloca [20 x i32], align 16
12 ; FULL-NEXT: %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
13 ; FULL-NEXT: call void @may_be_inlined()
14 ; FULL-NEXT: br label %for.body
16 ; PREPARE-LABEL: @test_prepare_for_lto(
17 ; PREPARE-NEXT: entry:
18 ; PREPARE-NEXT: %array = alloca [20 x i32], align 16
19 ; PREPARE-NEXT: br label %for.cond
22 %array = alloca [20 x i32], align 16
25 for.cond: ; preds = %for.body, %entry
26 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
27 %cmp = icmp slt i32 %i.0, 100
28 %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
29 call void @may_be_inlined()
30 br i1 %cmp, label %for.body, label %for.end
32 for.body: ; preds = %for.cond
33 store i32 0, i32* %arrayidx, align 16
34 %inc = add nsw i32 %i.0, 1
37 for.end: ; preds = %for.cond
41 define void @may_be_inlined() {
45 ; Intrinsics, like @llvm.dbg.value are never inlined and should not block loop
46 ; rotation, even when preparing for LTO.
47 define void @test_prepare_for_lto_intrinsic() !dbg !7 {
48 ; FULL-LABEL: @test_prepare_for_lto_intrinsic(
50 ; FULL-NEXT: %array = alloca [20 x i32], align 16
51 ; FULL-NEXT: call void @llvm.dbg.value(metadata i32 0, metadata !12, metadata !DIExpression()), !dbg !13
52 ; FULL-NEXT: %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
53 ; FULL-NEXT: br label %for.body
55 ; PREPARE-LABEL: @test_prepare_for_lto_intrinsic(
56 ; PREPARE-NEXT: entry:
57 ; PREPARE-NEXT: %array = alloca [20 x i32], align 16
58 ; PREPARE-NEXT: call void @llvm.dbg.value(metadata i32 0, metadata !12, metadata !DIExpression()), !dbg !13
59 ; PREPARE-NEXT: %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
60 ; PREPARE-NEXT: br label %for.body
63 %array = alloca [20 x i32], align 16
66 for.cond: ; preds = %for.body, %entry
67 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
68 call void @llvm.dbg.value(metadata i32 %i.0, metadata !12, metadata !DIExpression()), !dbg !13
69 %cmp = icmp slt i32 %i.0, 100
70 %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
71 br i1 %cmp, label %for.body, label %for.end
73 for.body: ; preds = %for.cond
74 store i32 0, i32* %arrayidx, align 16
75 %inc = add nsw i32 %i.0, 1
78 for.end: ; preds = %for.cond
82 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
86 !llvm.module.flags = !{!3, !4, !5, !6}
88 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
89 !1 = !DIFile(filename: "test.c", directory: "/tmp")
91 !3 = !{i32 2, !"Dwarf Version", i32 4}
92 !4 = !{i32 2, !"Debug Info Version", i32 3}
93 !5 = !{i32 1, !"wchar_size", i32 4}
94 !6 = !{i32 7, !"PIC Level", i32 2}
95 !7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
96 !8 = !DISubroutineType(types: !9)
98 !10 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
100 !12 = !DILocalVariable(name: "input", arg: 1, scope: !7, file: !1, line: 2, type: !10)
101 !13 = !DILocation(line: 2, column: 15, scope: !7)