https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89430
--- Comment #7 from Jiangning Liu <jiangning.liu at amperecomputing dot com> ---
To avoid "readonly" issue, try this case,
unsigned test(unsigned k, unsigned b) {
unsigned a[2];
if (b < a[k]) {
a[k] = b;
}
return a[0]+a[2];
}
Variable a is local, and it is NOT readonly, so now the following code is
generated,
sub sp, sp, #16
uxtw x0, w0
add x2, sp, 8
ldr w3, [x2, x0, lsl 2]
cmp w3, w1
bls .L2
str w1, [x2, x0, lsl 2]
.L2:
ldr w1, [sp, 8]
ldr w0, [sp, 16]
add sp, sp, 16
add w0, w1, w0
ret
But gcc should generate code below instead,
uxtw x2, w0
add x3, sp, 8
ldr w5, [sp, 16]
ldr w4, [x3, x2, lsl 2]
cmp w4, w1
csel w1, w1, w4, hi
str w1, [x3, x2, lsl 2]
ldr w0, [sp, 8]
add sp, sp, 16
add w0, w0, w5
ret
Any other glass jaw?