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

            Bug ID: 113231
           Summary: x86_64 use MMX instructions for simple shift
                    operations
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

Compiled with -Os, the following functions use MMX instructions for simple
shift.

------------------
void foo(int *i)
{
    *i *=2;
}

void bar(int *i)
{
    *i <<=2;
}

void baz(int *i)
{
    *i >>=2;
}
------------------

foo(int*):
        movd    xmm0, DWORD PTR [rdi]
        pslld   xmm0, 1
        movd    DWORD PTR [rdi], xmm0
        ret
bar(int*):
        movd    xmm0, DWORD PTR [rdi]
        pslld   xmm0, 2
        movd    DWORD PTR [rdi], xmm0
        ret
baz(int*):
        movd    xmm0, DWORD PTR [rdi]
        psrad   xmm0, 2
        movd    DWORD PTR [rdi], xmm0
        ret

-----------------

I would expect the generated code to use "sar" or "sal" instructions like O2
uses.

The functions used to generate optimal code with version 9.5.

Reply via email to