Closed
Description
static int Test(int[] arr) => arr[0];
Current codegen:
G_M50965_IG01:
A9BF7BFD stp fp, lr, [sp,#-16]!
910003FD mov fp, sp
;; bbWeight=1 PerfScore 1.50
G_M50965_IG02:
B9400801 ldr w1, [x0,#8]
7100003F cmp w1, #0
54000089 bls G_M50965_IG04
B9401000 ldr w0, [x0,#16]
;; bbWeight=1 PerfScore 7.50
G_M50965_IG03:
A8C17BFD ldp fp, lr, [sp],#16
D65F03C0 ret lr
;; bbWeight=1 PerfScore 2.00
G_M50965_IG04:
97FF2D9A bl CORINFO_HELP_RNGCHKFAIL
D4200000 brk #0
;; bbWeight=0 PerfScore 0.00
this
cmp w1, #0
bls G_M50965_IG04
can be optimized to:
cbz w1, G_M50965_IG04 ;; or CBNZ
branch if (not)zero.
Originally posted by @EgorBo in #42295 (comment)
@nathan-moore's analysis and prototype: #42295 (comment) :
@nathan-moore: I looked into what it will take to emit cbz here for arm. There isn't a way to emit it with genJumpToThrowHlpBlk, which is what everything currently uses. You can add a way, but since cbz is internally represented very differently from a normal jump, I don't see a good way of not duplicating the logic, which is what I did here: nathan-moore/runtime@8500e53. Does that seem like the right approach?
Also, I checked and there's already a peephole for this in the general case.
category:cq
theme:basic-cq
skill-level:beginner
cost:small
impact:small