public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/12508] New: weak optimization for some constants < 2^16
@ 2003-10-04 18:20 gpiez at users dot sourceforge dot net
  2003-10-04 21:22 ` [Bug optimization/12508] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: gpiez at users dot sourceforge dot net @ 2003-10-04 18:20 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: weak optimization for some constants < 2^16
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gpiez at users dot sourceforge dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

the function 
 
int f(int x) { 
    if (x & 0x1fff0) 
        return 1; 
    else 
        return 0; 
} 
 
compiled with '-O2 -fomit-framepointer' for a x86, yields 
 
        xor    %eax,%eax 
        testl  $0x1fff0,0x4(%esp,1) 
        setne  %al 
        ret 
 
This is ok (at least for me). But if I change the constant 0x1fff0 to 0xfff0,  
f() now looks like 
 
        mov    0x4(%esp,1),%eax 
        and    $0xfffffff0,%eax 
        test   %ax,%ax          <----- this is very ugly 
        setne  %al 
        movzbl %al,%eax 
        ret 
 
I suspect, the compiler wants to use the three bytes saving 'and imm8,%eax'  
instruction, but this doesn't make up for the additional 6 bytes it needs  
elsewhere. And the partial register read after a register write probably  
causes a stall, at least the second version did run 20% slower in a short  
test.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-01-27 13:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-04 18:20 [Bug optimization/12508] New: weak optimization for some constants < 2^16 gpiez at users dot sourceforge dot net
2003-10-04 21:22 ` [Bug optimization/12508] " pinskia at gcc dot gnu dot org
2003-10-04 21:28 ` pinskia at gcc dot gnu dot org
2003-11-24 20:50 ` kazu at cs dot umass dot edu
2003-12-24 22:01 ` kazu at cs dot umass dot edu
2003-12-24 22:09 ` pinskia at gcc dot gnu dot org
2003-12-25  0:10 ` [Bug optimization/12508] [3.4 regression] " kazu at cs dot umass dot edu
2003-12-25  0:22 ` pinskia at gcc dot gnu dot org
2003-12-26  0:35 ` kazu at cs dot umass dot edu
2004-01-12 19:42 ` cvs-commit at gcc dot gnu dot org
2004-01-12 19:44 ` pinskia at gcc dot gnu dot org
2004-01-27 13:12 ` cvs-commit at gcc dot gnu dot 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).