https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128049
Bug ID: 128049
Summary: [15/16/17 Regression] arm: redundant lsls before lsrs
when reading an unsigned bit-field on Thumb-1
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
Since GCC 15, reading an unsigned bit-field on Thumb-1 (Cortex-M0) at -Os emits
an extra lsls #16 before the shift right. ldrh already zero-extends the loaded
halfword, so a single lsrs #5 is enough.
struct U { unsigned x:5, y:11; };
unsigned get_uy (struct U *p)
{
return p->y;
}
Options: -mcpu=cortex-m0 -Os -mfloat-abi=soft
Checked on Godbolt.
arm-none-eabi-gcc 15.1: https://godbolt.org/z/czGTvdnfh
get_uy:
ldrh r0, [r0]
lsls r0, r0, #16
lsrs r0, r0, #21
bx lr
arm-none-eabi-gcc 14.3: https://godbolt.org/z/9Pha4ssh7
get_uy:
ldrh r0, [r0]
lsrs r0, r0, #5
bx lr
This only happens at -Os and other architectures are seemingly not affected.
Possibly related to r15-1575-gea8061f46a30 ("fwprop: invoke
change_is_worthwhile to judge if a replacement is worthwhile").