In 4.2 with -O2 -m32 -fomit-frame-pointer on x86_64:
unsigned int foo (unsigned int x)
{
  return (8 - (x & 7)) & 7;
}
results in andl $7, reg; negl reg; andl $7, reg.
On 4.3 apparently some RTL optimization catches this, but it is still a missed
tree optimization, fold should be able to fold:
(cst - (x & cstmask)) & cstmask2 as
(cst & cstmask2) + (-x & cstmask2) if x is unsigned or if -INT_MIN wraps to
INT_MIN, both cstmask and cstmask2 are constants z^2-1 for some z and
(cstmask & cstmask2) == cstmask2.
BTW, even for
(8 + (x & 7)) & 7
the optimized dump contains:
(x & 7) + 8 & 7
for both 4.2/4.3 (no idea why 8 & 7 hasn't been simplified as 0).


-- 
           Summary: Missed tree optimizations: (8 - (x & 7)) & 7
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261

Reply via email to