Files
clang-p2996/llvm/test/MachineVerifier/test_g_bzero.mir
Jessica Paquette 23f657c165 [AArch64][GlobalISel] Emit bzero on Darwin
Darwin platforms for both AArch64 and X86 can provide optimized `bzero()`
routines. In this case, it may be preferable to use `bzero` in place of a
memset of 0.

This adds a G_BZERO generic opcode, similar to G_MEMSET et al. This opcode can
be generated by platforms which may want to use bzero.

To emit the G_BZERO, this adds a pre-legalize combine for AArch64. The
conditions for this are largely a port of the bzero case in
`AArch64SelectionDAGInfo::EmitTargetCodeForMemset`.

The only difference in comparison to the SelectionDAG code is that, when
compiling for minsize, this will fire for all memsets of 0. The original code
notes that it's not beneficial to do this for small memsets; however, using
bzero here will save a mov from wzr. For minsize, I think that it's preferable
to prioritise omitting the mov.

This also fixes a bug in the libcall legalization code which would delete
instructions which could not be legalized. It also adds a check to make sure
that we actually get a libcall name.

Code size improvements (Darwin):

- CTMark -Os: -0.0% geomean (-0.1% on pairlocalalign)
- CTMark -Oz: -0.2% geomean (-0.5% on bullet)

Differential Revision: https://reviews.llvm.org/D99358
2021-03-25 17:14:25 -07:00

34 lines
1.0 KiB
YAML

#RUN: not --crash llc -o - -march=arm64 -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
# REQUIRES: aarch64-registered-target
---
name: test_bzero
legalized: true
regBankSelected: false
selected: false
tracksRegLiveness: true
liveins:
body: |
bb.0:
%ptr:_(p0) = G_IMPLICIT_DEF
%cst1:_(s64) = G_CONSTANT i64 4
%cst2:_(s8) = G_CONSTANT i8 7
; CHECK: *** Bad machine code: bzero must have 1 memory operand ***
G_BZERO %ptr, %cst2, 0
; CHECK: *** Bad machine code: bzero memory operand must be a store ***
G_BZERO %ptr, %cst2, 0 :: (load 4)
; CHECK: *** Bad machine code: Missing mayLoad flag ***
; CHECK: *** Bad machine code: bzero memory operand must be a store ***
G_BZERO %ptr, %cst2, 0 :: (load store 4)
; CHECK: *** Bad machine code: inconsistent bzero address space ***
G_BZERO %ptr, %cst2, 0 :: (store 4, addrspace 1)
; CHECK: *** Bad machine code: bzero operand must be a pointer ***
G_BZERO %cst1, %cst2, 0 :: (store 4)
...