1 ; RUN: llc %s -enable-machine-outliner=never -mtriple=arm64-apple-darwin -o - | FileCheck %s --check-prefix=DARWIN
2 ; RUN: llc %s -enable-machine-outliner=never -mtriple=arm64-linux-gnu -o - | FileCheck %s --check-prefix=LINUX
3 ; <rdar://problem/14199482> ARM64: Calls to bzero() replaced with calls to memset()
5 declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1)
8 ; Constant size memset to zero.
9 ; DARWIN: {{b|bl}} _bzero
10 ; LINUX: {{b|bl}} memset
11 define void @fct1(ptr nocapture %ptr) minsize {
12 tail call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 256, i1 false)
17 ; Variable size memset to zero.
18 ; DARWIN: {{b|bl}} _bzero
19 ; LINUX: {{b|bl}} memset
20 define void @fct3(ptr nocapture %ptr, i32 %unknown) minsize {
21 %conv = sext i32 %unknown to i64
22 tail call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 %conv, i1 false)
27 ; Variable size checked memset to zero.
28 ; DARWIN: {{b|bl}} _bzero
29 ; LINUX: {{b|bl}} memset
30 define void @fct4(ptr %ptr) minsize {
31 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
32 %call = tail call ptr @__memset_chk(ptr %ptr, i32 0, i64 256, i64 %tmp)
36 declare ptr @__memset_chk(ptr, i32, i64, i64)
38 declare i64 @llvm.objectsize.i64(ptr, i1)
41 ; Size = unknown, change.
42 ; DARWIN: {{b|bl}} _bzero
43 ; LINUX: {{b|bl}} memset
44 define void @fct6(ptr %ptr, i32 %unknown) minsize {
45 %conv = sext i32 %unknown to i64
46 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
47 %call = tail call ptr @__memset_chk(ptr %ptr, i32 0, i64 %conv, i64 %tmp)
51 ; Next functions check that memset is not turned into bzero
52 ; when the set constant is non-zero, whatever the given size.
55 ; memset with something that is not a zero, no change.
56 ; DARWIN: {{b|bl}} _memset
57 ; LINUX: {{b|bl}} memset
58 define void @fct7(ptr %ptr) minsize {
59 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
60 %call = tail call ptr @__memset_chk(ptr %ptr, i32 1, i64 256, i64 %tmp)
65 ; memset with something that is not a zero, no change.
66 ; DARWIN: {{b|bl}} _memset
67 ; LINUX: {{b|bl}} memset
68 define void @fct8(ptr %ptr) minsize {
69 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
70 %call = tail call ptr @__memset_chk(ptr %ptr, i32 1, i64 257, i64 %tmp)
75 ; memset with something that is not a zero, no change.
76 ; DARWIN: {{b|bl}} _memset
77 ; LINUX: {{b|bl}} memset
78 define void @fct9(ptr %ptr, i32 %unknown) minsize {
79 %conv = sext i32 %unknown to i64
80 %tmp = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false)
81 %call = tail call ptr @__memset_chk(ptr %ptr, i32 1, i64 %conv, i64 %tmp)