xref: /llvm-project/llvm/test/Transforms/InstCombine/fputs-opt-size.ll (revision 5fb9e840476d531cb5377c69941f2ccfe4145475)
1; When optimising for size, we don't want to rewrite fputs to fwrite
2; because it requires more arguments and thus extra MOVs are required.
3;
4; RUN: opt < %s -passes=instcombine -S | FileCheck %s
5; RUN: opt < %s -passes='require<profile-summary>,function(instcombine)' -pgso -S | FileCheck %s -check-prefix=PGSO
6; RUN: opt < %s -passes=instcombine -pgso=false -S | FileCheck %s -check-prefix=NPGSO
7
8%struct._IO_FILE = type { i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i16, i8, [1 x i8], ptr, i64, ptr, ptr, ptr, ptr, i32, i32, [40 x i8] }
9%struct._IO_marker = type { ptr, ptr, i32 }
10
11@.str = private unnamed_addr constant [10 x i8] c"mylog.txt\00", align 1
12@.str.1 = private unnamed_addr constant [2 x i8] c"a\00", align 1
13@.str.2 = private unnamed_addr constant [27 x i8] c"Hello world this is a test\00", align 1
14
15define i32 @main() local_unnamed_addr #0 {
16entry:
17; CHECK-LABEL: @main(
18; CHECK-NOT: call i64 @fwrite
19; CHECK: call i32 @fputs
20
21  %call = tail call ptr @fopen(ptr @.str, ptr @.str.1) #2
22  %call1 = tail call i32 @fputs(ptr @.str.2, ptr %call) #2
23  ret i32 0
24}
25
26declare noalias ptr @fopen(ptr nocapture readonly, ptr nocapture readonly) local_unnamed_addr #1
27declare i32 @fputs(ptr nocapture readonly, ptr nocapture) local_unnamed_addr #1
28
29attributes #0 = { nounwind optsize }
30attributes #1 = { nounwind optsize  }
31
32define i32 @main_pgso() local_unnamed_addr !prof !14 {
33entry:
34; PGSO-LABEL: @main_pgso(
35; PGSO-NOT: call i64 @fwrite
36; PGSO: call i32 @fputs
37; NPGSO-LABEL: @main_pgso(
38; NPGSO: call i64 @fwrite
39; NPGSO-NOT: call i32 @fputs
40
41  %call = tail call ptr @fopen(ptr @.str, ptr @.str.1) #2
42  %call1 = tail call i32 @fputs(ptr @.str.2, ptr %call) #2
43  ret i32 0
44}
45
46!llvm.module.flags = !{!0}
47!0 = !{i32 1, !"ProfileSummary", !1}
48!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
49!2 = !{!"ProfileFormat", !"InstrProf"}
50!3 = !{!"TotalCount", i64 10000}
51!4 = !{!"MaxCount", i64 10}
52!5 = !{!"MaxInternalCount", i64 1}
53!6 = !{!"MaxFunctionCount", i64 1000}
54!7 = !{!"NumCounts", i64 3}
55!8 = !{!"NumFunctions", i64 3}
56!9 = !{!"DetailedSummary", !10}
57!10 = !{!11, !12, !13}
58!11 = !{i32 10000, i64 100, i32 1}
59!12 = !{i32 999000, i64 100, i32 1}
60!13 = !{i32 999999, i64 1, i32 2}
61!14 = !{!"function_entry_count", i64 0}
62