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

            Bug ID: 103535
           Summary: [missed optimization] remainder-of-2 with subtract-1
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jengelh at inai dot de
  Target Milestone: ---

gcc version 11.2.1 20210816 [revision 056e324ce46a7924b5cf10f61010cf9dd2ca10e9]
(SUSE Linux)  x86_64

== input ==
unsigned int fff(unsigned int p)
{
        // equivalent to  return p & ~1;
        if (p % 2 != 0)
                --p;
        return p;
}

== Observed output ==
ยป gcc -O2 -c x.cpp; objdump -Mintel -d x.o
   0:   89 fa                   mov    edx,edi
   2:   89 f8                   mov    eax,edi
   4:   83 e2 01                and    edx,0x1
   7:   83 fa 01                cmp    edx,0x1
   a:   83 d0 ff                adc    eax,0xffffffff
   d:   c3                      ret    

== Expected output ==
   0:   89 f8                   mov    eax,edi
   2:   83 e0 fe                and    eax,0xfffffffe
   5:   c3                      ret

Reply via email to