Home | History | Annotate | Download | only in AArch64
      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()
      6 
      7 ; CHECK-LABEL: fct1:
      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 {
     12 entry:
     13   tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 256, i1 false)
     14   ret void
     15 }
     16 
     17 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1)
     18 
     19 ; CHECK-LABEL: fct2:
     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 {
     24 entry:
     25   tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 257, i1 false)
     26   ret void
     27 }
     28 
     29 ; CHECK-LABEL: fct3:
     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 {
     34 entry:
     35   %conv = sext i32 %unknown to i64
     36   tail call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 %conv, i1 false)
     37   ret void
     38 }
     39 
     40 ; CHECK-LABEL: fct4:
     41 ; Size <= 256, no change.
     42 ; CHECK-DARWIN: {{b|bl}} _memset
     43 ; CHECK-LINUX: {{b|bl}} memset
     44 define void @fct4(i8* %ptr) minsize {
     45 entry:
     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)
     48   ret void
     49 }
     50 
     51 declare i8* @__memset_chk(i8*, i32, i64, i64)
     52 
     53 declare i64 @llvm.objectsize.i64(i8*, i1)
     54 
     55 ; CHECK-LABEL: fct5:
     56 ; Size > 256, change.
     57 ; CHECK-DARWIN: {{b|bl}} _bzero
     58 ; CHECK-LINUX: {{b|bl}} memset
     59 define void @fct5(i8* %ptr) minsize {
     60 entry:
     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)
     63   ret void
     64 }
     65 
     66 ; CHECK-LABEL: fct6:
     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 {
     71 entry:
     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)
     75   ret void
     76 }
     77 
     78 ; Next functions check that memset is not turned into bzero
     79 ; when the set constant is non-zero, whatever the given size.
     80 
     81 ; CHECK-LABEL: fct7:
     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 {
     86 entry:
     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)
     89   ret void
     90 }
     91 
     92 ; CHECK-LABEL: fct8:
     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 {
     97 entry:
     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)
    100   ret void
    101 }
    102 
    103 ; CHECK-LABEL: fct9:
    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 {
    108 entry:
    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)
    112   ret void
    113 }
    114