public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/24696]  New: missing optimization in comparison of results of bit operations
@ 2005-11-06 17:06 drepper at redhat dot com
  2005-11-06 17:15 ` [Bug tree-optimization/24696] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: drepper at redhat dot com @ 2005-11-06 17:06 UTC (permalink / raw)
  To: gcc-bugs

Take this little program:

int
f (unsigned long a, unsigned long b, unsigned long c)
{
  return (a & (c - 1)) != 0 || (b & (c - 1)) != 0;
}

Compiled on x86-64 with gcc 4.0.2 (but I think also with the current mainline)
yields with -O2 the following code:

0000000000000000 <f>:
   0:   48 ff ca                dec    %rdx
   3:   48 85 d7                test   %rdx,%rdi
   6:   75 07                   jne    f <f+0xf>
   8:   31 c0                   xor    %eax,%eax
   a:   48 85 d6                test   %rdx,%rsi
   d:   74 05                   je     14 <f+0x14>
   f:   b8 01 00 00 00          mov    $0x1,%eax
  14:   f3 c3                   repz retq

As can be seen, both comparisons are executed individually.  This is
unnecessarily slow.  Since the right operand for & is the same and this is a
pure bit-test it is perfectly fine to compile the code to the equivalent of

int
f (unsigned long a, unsigned long b, unsigned long c)
{
  return ((a | b) & (c - 1)) != 0;
}

This would be significantly faster.  On archs like x86-64 no conditional jump
(just a setne) would be needed.


-- 
           Summary: missing optimization in comparison of results of bit
                    operations
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: drepper at redhat dot com


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


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

* [Bug tree-optimization/24696] missing optimization in comparison of results of bit operations
  2005-11-06 17:06 [Bug tree-optimization/24696] New: missing optimization in comparison of results of bit operations drepper at redhat dot com
@ 2005-11-06 17:15 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-06 17:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2005-11-06 17:14 -------
The mainline gives:
f:
.LFB2:
        decq    %rdx
        movl    $1, %eax
        testq   %rdi, %rdx
        jne     .L4
        xorl    %eax, %eax
        testq   %rsi, %rdx
        setne   %al
.L4:
        rep ; ret
This is because of the improved PHI-OPT which I added but this is still not
fully optimized.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2005-11-06 17:14:59
               date|                            |


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


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

end of thread, other threads:[~2005-11-06 17:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-06 17:06 [Bug tree-optimization/24696] New: missing optimization in comparison of results of bit operations drepper at redhat dot com
2005-11-06 17:15 ` [Bug tree-optimization/24696] " pinskia 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).