# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple aarch64-apple-ios -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=DARWIN
# RUN: llc -mtriple aarch64 -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=UNKNOWN
#
# Check that on Darwin we can combine to G_BZERO. Without Darwin, this should
# stay as memset.
--- |
define void @bzero_unknown_width() { unreachable }
define void @bzero_tail_unknown_width() { unreachable }
define void @bzero_constant_width() { unreachable }
define void @bzero_constant_width_minsize() minsize { unreachable }
define void @not_zero() minsize { unreachable }
...
---
name: bzero_unknown_width
tracksRegLiveness: true
body: |
bb.0:
liveins: $x0, $x1
; Always use G_BZERO when the memset width is unknown on Darwin.
; DARWIN-LABEL: name: bzero_unknown_width
; DARWIN: liveins: $x0, $x1
; DARWIN-NEXT: {{ $}}
; DARWIN-NEXT: %ptr:_(p0) = COPY $x0
; DARWIN-NEXT: %width:_(s64) = COPY $x1
; DARWIN-NEXT: G_BZERO %ptr(p0), %width(s64), 0 :: (store (s32))
; DARWIN-NEXT: RET_ReallyLR
;
; UNKNOWN-LABEL: name: bzero_unknown_width
; UNKNOWN: liveins: $x0, $x1
; UNKNOWN-NEXT: {{ $}}
; UNKNOWN-NEXT: %ptr:_(p0) = COPY $x0
; UNKNOWN-NEXT: %zero:_(s8) = G_CONSTANT i8 0
; UNKNOWN-NEXT: %width:_(s64) = COPY $x1
; UNKNOWN-NEXT: G_MEMSET %ptr(p0), %zero(s8), %width(s64), 0 :: (store (s32))
; UNKNOWN-NEXT: RET_ReallyLR
%ptr:_(p0) = COPY $x0
%zero:_(s8) = G_CONSTANT i8 0
%width:_(s64) = COPY $x1
G_MEMSET %ptr(p0), %zero(s8), %width(s64), 0 :: (store (s32))
RET_ReallyLR
...
---
name: bzero_tail_unknown_width
tracksRegLiveness: true
body: |
bb.0:
liveins: $x0, $x1
; DARWIN-LABEL: name: bzero_tail_unknown_width
; DARWIN: liveins: $x0, $x1
; DARWIN-NEXT: {{ $}}
; DARWIN-NEXT: %ptr:_(p0) = COPY $x0
; DARWIN-NEXT: %width:_(s64) = COPY $x1
; DARWIN-NEXT: G_BZERO %ptr(p0), %width(s64), 1 :: (store (s32))
; DARWIN-NEXT: RET_ReallyLR
;
; UNKNOWN-LABEL: name: bzero_tail_unknown_width
; UNKNOWN: liveins: $x0, $x1
; UNKNOWN-NEXT: {{ $}}
; UNKNOWN-NEXT: %ptr:_(p0) = COPY $x0
; UNKNOWN-NEXT: %zero:_(s8) = G_CONSTANT i8 0
; UNKNOWN-NEXT: %width:_(s64) = COPY $x1
; UNKNOWN-NEXT: G_MEMSET %ptr(p0), %zero(s8), %width(s64), 1 :: (store (s32))
; UNKNOWN-NEXT: RET_ReallyLR
%ptr:_(p0) = COPY $x0
%zero:_(s8) = G_CONSTANT i8 0
%width:_(s64) = COPY $x1
G_MEMSET %ptr(p0), %zero(s8), %width(s64), 1 :: (store (s32))
RET_ReallyLR
...
---
name: bzero_constant_width
tracksRegLiveness: true
body: |
bb.0:
liveins: $x0, $x1
; For values >256, we should use G_BZERO on Darwin.
; DARWIN-LABEL: name: bzero_constant_width
; DARWIN: liveins: $x0, $x1
; DARWIN-NEXT: {{ $}}
; DARWIN-NEXT: %ptr:_(p0) = COPY $x0
; DARWIN-NEXT: %width:_(s64) = G_CONSTANT i64 1024
; DARWIN-NEXT: G_BZERO %ptr(p0), %width(s64), 0 :: (store (s32))
; DARWIN-NEXT: RET_ReallyLR
;
; UNKNOWN-LABEL: name: bzero_constant_width
; UNKNOWN: liveins: $x0, $x1
; UNKNOWN-NEXT: {{ $}}
; UNKNOWN-NEXT: %ptr:_(p0) = COPY $x0
; UNKNOWN-NEXT: %zero:_(s8) = G_CONSTANT i8 0
; UNKNOWN-NEXT: %width:_(s64) = G_CONSTANT i64 1024
; UNKNOWN-NEXT: G_MEMSET %ptr(p0), %zero(s8), %width(s64), 0 :: (store (s32))
; UNKNOWN-NEXT: RET_ReallyLR
%ptr:_(p0) = COPY $x0
%zero:_(s8) = G_CONSTANT i8 0
%width:_(s64) = G_CONSTANT i64 1024
G_MEMSET %ptr(p0), %zero(s8), %width(s64), 0 :: (store (s32))
RET_ReallyLR
...
---
name: bzero_constant_width_minsize
tracksRegLiveness: true
body: |
bb.0:
liveins: $x0, $x1
; With minsize, we should always use G_BZERO to avoid a copy from wzr.
; DARWIN-LABEL: name: bzero_constant_width_minsize
; DARWIN: liveins: $x0, $x1
; DARWIN-NEXT: {{ $}}
; DARWIN-NEXT: %ptr:_(p0) = COPY $x0
; DARWIN-NEXT: %width:_(s64) = G_CONSTANT i64 256
; DARWIN-NEXT: G_BZERO %ptr(p0), %width(s64), 0 :: (store (s32))
; DARWIN-NEXT: RET_ReallyLR
;
; UNKNOWN-LABEL: name: bzero_constant_width_minsize
; UNKNOWN: liveins: $x0, $x1
; UNKNOWN-NEXT: {{ $}}
; UNKNOWN-NEXT: %ptr:_(p0) = COPY $x0
; UNKNOWN-NEXT: %zero:_(s8) = G_CONSTANT i8 0
; UNKNOWN-NEXT: %width:_(s64) = G_CONSTANT i64 256
; UNKNOWN-NEXT: G_MEMSET %ptr(p0), %zero(s8), %width(s64), 0 :: (store (s32))
; UNKNOWN-NEXT: RET_ReallyLR
%ptr:_(p0) = COPY $x0
%zero:_(s8) = G_CONSTANT i8 0
%width:_(s64) = G_CONSTANT i64 256
G_MEMSET %ptr(p0), %zero(s8), %width(s64), 0 :: (store (s32))
RET_ReallyLR
...
---
name: not_zero
tracksRegLiveness: true
body: |
bb.0:
liveins: $x0, $x1
; When the value isn't 0, don't create G_BZERO.
; DARWIN-LABEL: name: not_zero
; DARWIN: liveins: $x0, $x1
; DARWIN-NEXT: {{ $}}
; DARWIN-NEXT: %ptr:_(p0) = COPY $x0
; DARWIN-NEXT: %not_zero:_(s8) = G_CONSTANT i8 1
; DARWIN-NEXT: %width:_(s64) = G_CONSTANT i64 256
; DARWIN-NEXT: G_MEMSET %ptr(p0), %not_zero(s8), %width(s64), 0 :: (store (s32))
; DARWIN-NEXT: RET_ReallyLR
;
; UNKNOWN-LABEL: name: not_zero
; UNKNOWN: liveins: $x0, $x1
; UNKNOWN-NEXT: {{ $}}
; UNKNOWN-NEXT: %ptr:_(p0) = COPY $x0
; UNKNOWN-NEXT: %not_zero:_(s8) = G_CONSTANT i8 1
; UNKNOWN-NEXT: %width:_(s64) = G_CONSTANT i64 256
; UNKNOWN-NEXT: G_MEMSET %ptr(p0), %not_zero(s8), %width(s64), 0 :: (store (s32))
; UNKNOWN-NEXT: RET_ReallyLR
%ptr:_(p0) = COPY $x0
%not_zero:_(s8) = G_CONSTANT i8 1
%width:_(s64) = G_CONSTANT i64 256
G_MEMSET %ptr(p0), %not_zero(s8), %width(s64), 0 :: (store (s32))
RET_ReallyLR