1; RUN: llc %s -mtriple=arm64-apple-darwin -o - | \ 2; RUN: FileCheck --check-prefix=CHECK-DARWIN --check-prefix=CHECK %s 3; RUN: llc %s -mtriple=arm64-linux-gnu -o - | \ 4; RUN: FileCheck --check-prefix=CHECK-LINUX --check-prefix=CHECK %s 5; <rdar://problem/14199482> ARM64: Calls to bzero() replaced with calls to memset() 6 7; CHECK: @fct1 8; For small size (<= 256), we do not change memset to bzero. 9; CHECK: memset 10define void @fct1(i8* nocapture %ptr) { 11entry: 12 tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 256, i32 1, i1 false) 13 ret void 14} 15 16declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) 17 18; CHECK: @fct2 19; When the size is bigger than 256, change into bzero. 20; CHECK-DARWIN: bzero 21; CHECK-LINUX: memset 22define void @fct2(i8* nocapture %ptr) { 23entry: 24 tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 257, i32 1, i1 false) 25 ret void 26} 27 28; CHECK: @fct3 29; For unknown size, change to bzero. 30; CHECK-DARWIN: bzero 31; CHECK-LINUX: memset 32define void @fct3(i8* nocapture %ptr, i32 %unknown) { 33entry: 34 %conv = sext i32 %unknown to i64 35 tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 %conv, i32 1, i1 false) 36 ret void 37} 38 39; CHECK: @fct4 40; Size <= 256, no change. 41; CHECK: memset 42define void @fct4(i8* %ptr) { 43entry: 44 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false) 45 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 256, i64 %tmp) 46 ret void 47} 48 49declare i8* @__memset_chk(i8*, i32, i64, i64) 50 51declare i64 @llvm.objectsize.i64(i8*, i1) 52 53; CHECK: @fct5 54; Size > 256, change. 55; CHECK-DARWIN: bzero 56; CHECK-LINUX: memset 57define void @fct5(i8* %ptr) { 58entry: 59 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false) 60 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 257, i64 %tmp) 61 ret void 62} 63 64; CHECK: @fct6 65; Size = unknown, change. 66; CHECK-DARWIN: bzero 67; CHECK-LINUX: memset 68define void @fct6(i8* %ptr, i32 %unknown) { 69entry: 70 %conv = sext i32 %unknown to i64 71 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false) 72 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 %conv, i64 %tmp) 73 ret void 74} 75 76; Next functions check that memset is not turned into bzero 77; when the set constant is non-zero, whatever the given size. 78 79; CHECK: @fct7 80; memset with something that is not a zero, no change. 81; CHECK: memset 82define void @fct7(i8* %ptr) { 83entry: 84 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false) 85 %call = tail call i8* @__memset_chk(i8* %ptr, i32 1, i64 256, i64 %tmp) 86 ret void 87} 88 89; CHECK: @fct8 90; memset with something that is not a zero, no change. 91; CHECK: memset 92define void @fct8(i8* %ptr) { 93entry: 94 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false) 95 %call = tail call i8* @__memset_chk(i8* %ptr, i32 1, i64 257, i64 %tmp) 96 ret void 97} 98 99; CHECK: @fct9 100; memset with something that is not a zero, no change. 101; CHECK: memset 102define void @fct9(i8* %ptr, i32 %unknown) { 103entry: 104 %conv = sext i32 %unknown to i64 105 %tmp = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false) 106 %call = tail call i8* @__memset_chk(i8* %ptr, i32 1, i64 %conv, i64 %tmp) 107 ret void 108} 109