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

            Bug ID: 120410
           Summary: [15/16 Regression] [SH] XTRCT instruction is no longer
                    selected for shift after multiplication
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zack+gcc at buhman dot org
  Target Milestone: ---
            Target: sh*-*-*

Fixed point multiplication, as in:

int32_t fpmul_16_16(int32_t a, int32_t b)
{
    int64_t tmp = (int64_t)a * (int64_t)b;
    return tmp >> 16;
}

Is a common pattern on SH-2.

This function should be compiled as, and the GCC code generation in all
versions from versions 4 through 14 inclusive was:

        dmuls.l r5,r4
        sts     macl,r0
        sts     mach,r1
        rts     
        xtrct   r1,r0

However, GCC >= 15.1 compiles the function as:

        dmuls.l r5,r4
        sts     macl,r0
        sts     mach,r1
        shll16  r1
        shlr16  r0
        rts     
        add     r1,r0

This is a fairly impactful regression for the typical use-case for SH-2, where
large numbers of fixed-point multiplications are performed.

I confirmed this regression exists both in GCC 15.1 and the latest GCC 16
master.

https://godbolt.org/z/zaoPreK7b

Reply via email to