1 ; RUN: llc %s -enable-machine-outliner=never -mtriple=arm64-apple-darwin -o - \
2 ; RUN: | FileCheck --check-prefixes=CHECK,CHECK-DARWIN %s
3 ; RUN: llc %s -enable-machine-outliner=never -mtriple=arm64-linux-gnu -o - | \
4 ; RUN: FileCheck --check-prefixes=CHECK,CHECK-LINUX %s
5 ; <rdar://problem/14199482> ARM64: Calls to bzero() replaced with calls to memset()
8 ; For small size (<= 256), we do not change memset to bzero.
9 ; CHECK-DARWIN: {{b|bl}} _memset
10 ; CHECK-LINUX: {{b|bl}} memset
11 define void @fct1(i8* nocapture %ptr) minsize {
13 tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 256, i1 false)
17 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1)
20 ; When the size is bigger than 256, change into bzero.
21 ; CHECK-DARWIN: {{b|bl}} _bzero
22 ; CHECK-LINUX: {{b|bl}} memset
23 define void @fct2(i8* nocapture %ptr) minsize {
25 tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 257, i1 false)
30 ; For unknown size, change to bzero.
31 ; CHECK-DARWIN: {{b|bl}} _bzero
32 ; CHECK-LINUX: {{b|bl}} memset
33 define void @fct3(i8* nocapture %ptr, i32 %unknown) minsize {
35 %conv = sext i32 %unknown to i64
36 tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 %conv, i1 false)
41 ; Size <= 256, no change.
42 ; CHECK-DARWIN: {{b|bl}} _memset
43 ; CHECK-LINUX: {{b|bl}} memset
44 define void @fct4(i8* %ptr) minsize {
46 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
47 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 256, i64 %tmp)
51 declare i8* @__memset_chk(i8*, i32, i64, i64)
53 declare i64 @llvm.objectsize.i64(i8*, i1)
57 ; CHECK-DARWIN: {{b|bl}} _bzero
58 ; CHECK-LINUX: {{b|bl}} memset
59 define void @fct5(i8* %ptr) minsize {
61 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
62 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 257, i64 %tmp)
67 ; Size = unknown, change.
68 ; CHECK-DARWIN: {{b|bl}} _bzero
69 ; CHECK-LINUX: {{b|bl}} memset
70 define void @fct6(i8* %ptr, i32 %unknown) minsize {
72 %conv = sext i32 %unknown to i64
73 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
74 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 %conv, i64 %tmp)
78 ; Next functions check that memset is not turned into bzero
79 ; when the set constant is non-zero, whatever the given size.
82 ; memset with something that is not a zero, no change.
83 ; CHECK-DARWIN: {{b|bl}} _memset
84 ; CHECK-LINUX: {{b|bl}} memset
85 define void @fct7(i8* %ptr) minsize {
87 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
88 %call = tail call i8* @__memset_chk(i8* %ptr, i32 1, i64 256, i64 %tmp)
93 ; memset with something that is not a zero, no change.
94 ; CHECK-DARWIN: {{b|bl}} _memset
95 ; CHECK-LINUX: {{b|bl}} memset
96 define void @fct8(i8* %ptr) minsize {
98 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
99 %call = tail call i8* @__memset_chk(i8* %ptr, i32 1, i64 257, i64 %tmp)
104 ; memset with something that is not a zero, no change.
105 ; CHECK-DARWIN: {{b|bl}} _memset
106 ; CHECK-LINUX: {{b|bl}} memset
107 define void @fct9(i8* %ptr, i32 %unknown) minsize {
109 %conv = sext i32 %unknown to i64
110 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
111 %call = tail call i8* @__memset_chk(i8* %ptr, i32 1, i64 %conv, i64 %tmp)