1 ; RUN: llc %s -enable-machine-outliner=never -mtriple=arm64-linux-gnu -o - | \
2 ; RUN: FileCheck --check-prefixes=CHECK,CHECK-LINUX %s
3 ; <rdar://problem/14199482> ARM64: Calls to bzero() replaced with calls to memset()
6 ; For small size (<= 256), we do not change memset to bzero.
7 ; CHECK-DARWIN: {{b|bl}} _memset
8 ; CHECK-LINUX: {{b|bl}} memset
9 define void @fct1(ptr nocapture %ptr) !prof !14 {
11 tail call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 256, i1 false)
15 declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1)
18 ; When the size is bigger than 256, change into bzero.
19 ; CHECK-DARWIN: {{b|bl}} _bzero
20 ; CHECK-LINUX: {{b|bl}} memset
21 define void @fct2(ptr nocapture %ptr) !prof !14 {
23 tail call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 257, i1 false)
28 ; For unknown size, change to bzero.
29 ; CHECK-DARWIN: {{b|bl}} _bzero
30 ; CHECK-LINUX: {{b|bl}} memset
31 define void @fct3(ptr nocapture %ptr, i32 %unknown) !prof !14 {
33 %conv = sext i32 %unknown to i64
34 tail call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 %conv, i1 false)
39 ; Size <= 256, no change.
40 ; CHECK-DARWIN: {{b|bl}} _memset
41 ; CHECK-LINUX: {{b|bl}} memset
42 define void @fct4(ptr %ptr) !prof !14 {
44 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
45 %call = tail call ptr @__memset_chk(ptr %ptr, i32 0, i64 256, i64 %tmp)
49 declare ptr @__memset_chk(ptr, i32, i64, i64)
51 declare i64 @llvm.objectsize.i64(ptr, i1)
55 ; CHECK-DARWIN: {{b|bl}} _bzero
56 ; CHECK-LINUX: {{b|bl}} memset
57 define void @fct5(ptr %ptr) !prof !14 {
59 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
60 %call = tail call ptr @__memset_chk(ptr %ptr, i32 0, i64 257, i64 %tmp)
65 ; Size = unknown, change.
66 ; CHECK-DARWIN: {{b|bl}} _bzero
67 ; CHECK-LINUX: {{b|bl}} memset
68 define void @fct6(ptr %ptr, i32 %unknown) !prof !14 {
70 %conv = sext i32 %unknown to i64
71 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
72 %call = tail call ptr @__memset_chk(ptr %ptr, i32 0, i64 %conv, i64 %tmp)
76 ; Next functions check that memset is not turned into bzero
77 ; when the set constant is non-zero, whatever the given size.
80 ; memset with something that is not a zero, no change.
81 ; CHECK-DARWIN: {{b|bl}} _memset
82 ; CHECK-LINUX: {{b|bl}} memset
83 define void @fct7(ptr %ptr) !prof !14 {
85 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
86 %call = tail call ptr @__memset_chk(ptr %ptr, i32 1, i64 256, i64 %tmp)
91 ; memset with something that is not a zero, no change.
92 ; CHECK-DARWIN: {{b|bl}} _memset
93 ; CHECK-LINUX: {{b|bl}} memset
94 define void @fct8(ptr %ptr) !prof !14 {
96 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
97 %call = tail call ptr @__memset_chk(ptr %ptr, i32 1, i64 257, i64 %tmp)
102 ; memset with something that is not a zero, no change.
103 ; CHECK-DARWIN: {{b|bl}} _memset
104 ; CHECK-LINUX: {{b|bl}} memset
105 define void @fct9(ptr %ptr, i32 %unknown) !prof !14 {
107 %conv = sext i32 %unknown to i64
108 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
109 %call = tail call ptr @__memset_chk(ptr %ptr, i32 1, i64 %conv, i64 %tmp)
113 !llvm.module.flags = !{!0}
114 !0 = !{i32 1, !"ProfileSummary", !1}
115 !1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
116 !2 = !{!"ProfileFormat", !"InstrProf"}
117 !3 = !{!"TotalCount", i64 10000}
118 !4 = !{!"MaxCount", i64 10}
119 !5 = !{!"MaxInternalCount", i64 1}
120 !6 = !{!"MaxFunctionCount", i64 1000}
121 !7 = !{!"NumCounts", i64 3}
122 !8 = !{!"NumFunctions", i64 3}
123 !9 = !{!"DetailedSummary", !10}
124 !10 = !{!11, !12, !13}
125 !11 = !{i32 10000, i64 100, i32 1}
126 !12 = !{i32 999000, i64 100, i32 1}
127 !13 = !{i32 999999, i64 1, i32 2}
128 !14 = !{!"function_entry_count", i64 0}