starts_with_a:
cbz x1, .LBB0_2
ldrb w8, [x0]
cmp w8, #97
cset w8, eq
cmp x1, #0
cset w9, ne
and w0, w9, w8
ret
.LBB0_2:
cmp x1, #0
cset w9, ne
and w0, w9, w8
ret
The cmp x1, #0 in each branch is implied true/false by the cbz x1 test.
The optimal assembly can be produced by removing the select in the final basic block:
This rust code produces sub-optimal assembly:
https://godbolt.org/z/Ex7jKGzj7
The
cmp x1, #0
in each branch is implied true/false by thecbz x1
test. The optimal assembly can be produced by removing theselect
in the final basic block:https://godbolt.org/z/87MKvPjf6 https://alive2.llvm.org/ce/z/VofZ27