https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128048

            Bug ID: 128048
           Summary: [17 Regression] arm: redundant sxth after sbfx when
                    reading a signed bit-field
           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 17, reading a signed bit-field on Thumb-2 (Cortex-M3) emits an extra
sxth after the sbfx. The sbfx already sign-extends the field, so the sxth is
redundant.

struct i { int x : 5; int y : 11; };

int get_iy (struct i *p) { return p->y; }

Options: -mcpu=cortex-m3 -O2 -mthumb
Checked on Godbolt.

arm-none-eabi-gcc trunk: https://godbolt.org/z/5PjxYqGTT

get_iy:
        ldrh    r0, [r0]
        sbfx    r0, r0, #5, #11
        sxth    r0, r0
        bx      lr

arm-none-eabi-gcc 16.1: https://godbolt.org/z/PEf7Pqq56

get_iy:
        ldrh    r0, [r0]
        sbfx    r0, r0, #5, #11
        bx      lr

Possibly caused by r17-2413-ge46d96d20bbf ("PR middle-end/123236: Simplify
(int)((long long)x >> 4)").
  • [Bug target/128048] New: [1... yuki.tanaka at defaultcase dot de via Gcc-bugs

Reply via email to