public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/31261]  New: Missed tree optimizations: (8 - (x & 7)) & 7
@ 2007-03-19 11:05 jakub at gcc dot gnu dot org
  2007-03-19 11:17 ` [Bug tree-optimization/31261] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-03-19 11:05 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <bug-31261-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2010-09-30 19:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19 11:05 [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7 jakub at gcc dot gnu dot org
2007-03-19 11:17 ` [Bug tree-optimization/31261] " rguenth at gcc dot gnu dot org
2007-03-19 11:19 ` rguenth at gcc dot gnu dot org
2007-03-21 15:06 ` jakub at gcc dot gnu dot org
2007-03-21 18:28 ` trt at acm dot org
     [not found] <bug-31261-4@http.gcc.gnu.org/bugzilla/>
2010-09-30 21:23 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).