public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32648]  New: missed-optimization: bit-manipulation via bool's
@ 2007-07-06 12:25 wouter dot vermaelen at scarlet dot be
  2007-07-06 12:54 ` [Bug tree-optimization/32648] " rguenth at gcc dot gnu dot org
  2007-07-07  3:10 ` rob1weld at aol dot com
  0 siblings, 2 replies; 5+ messages in thread
From: wouter dot vermaelen at scarlet dot be @ 2007-07-06 12:25 UTC (permalink / raw)
  To: gcc-bugs

> cat b5-xor-b3.cc
bool f1(int a)
{
        bool b5 = a & 0x20;
        bool b3 = a & 0x08;
        return b5 ^ b3;
}
bool f2(int a)
{
        return (a ^ (a << 2)) & 0x20;
}

> g++ -O3 -c b5-xor-b3.cc
> objdump -d b5-xor-b3.o

b5-xor-b3.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <_Z2f1i>:
   0:   c1 ef 03                shr    $0x3,%edi
   3:   89 f8                   mov    %edi,%eax
   5:   c1 ef 02                shr    $0x2,%edi
   8:   83 e0 01                and    $0x1,%eax
   b:   83 e7 01                and    $0x1,%edi
   e:   40 38 f8                cmp    %dil,%al
  11:   0f 95 c0                setne  %al
  14:   0f b6 c0                movzbl %al,%eax
  17:   c3                      retq
  18:   0f 1f 84 00 00 00 00    nopl   0x0(%rax,%rax,1)
  1f:   00

0000000000000020 <_Z2f2i>:
  20:   8d 04 bd 00 00 00 00    lea    0x0(,%rdi,4),%eax
  27:   31 f8                   xor    %edi,%eax
  29:   c1 e8 05                shr    $0x5,%eax
  2c:   83 e0 01                and    $0x1,%eax
  2f:   c3                      retq


-- 
           Summary: missed-optimization: bit-manipulation via bool's
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wouter dot vermaelen at scarlet dot be


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


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

* [Bug tree-optimization/32648] missed-optimization: bit-manipulation via bool's
  2007-07-06 12:25 [Bug c++/32648] New: missed-optimization: bit-manipulation via bool's wouter dot vermaelen at scarlet dot be
@ 2007-07-06 12:54 ` rguenth at gcc dot gnu dot org
  2007-07-07  3:10 ` rob1weld at aol dot com
  1 sibling, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-07-06 12:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2007-07-06 12:54 -------
Confirmed.  This needs VRP of bits.  The IL we generate is currently

  bool b3;
  bool b5;
  int D.2483;
  int D.2482;
  int D.2481;

<bb 2>:
  D.2481_2 = a_1(D) & 32;
  b5_3 = D.2481_2 != 0;
  D.2482_4 = a_1(D) & 8;
  b3_5 = D.2482_4 != 0;
  D.2483_6 = b5_3 != b3_5;
  return D.2483_6;


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |tree-optimization
     Ever Confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2007-07-06 12:54:02
               date|                            |


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


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

* [Bug tree-optimization/32648] missed-optimization: bit-manipulation via bool's
  2007-07-06 12:25 [Bug c++/32648] New: missed-optimization: bit-manipulation via bool's wouter dot vermaelen at scarlet dot be
  2007-07-06 12:54 ` [Bug tree-optimization/32648] " rguenth at gcc dot gnu dot org
@ 2007-07-07  3:10 ` rob1weld at aol dot com
  1 sibling, 0 replies; 5+ messages in thread
From: rob1weld at aol dot com @ 2007-07-07  3:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rob1weld at aol dot com  2007-07-07 03:10 -------
There is a whole list of these optimizations at:
http://graphics.stanford.edu/~seander/bithacks.html


-- 


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


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

* [Bug tree-optimization/32648] missed-optimization: bit-manipulation via bool's
       [not found] <bug-32648-4@http.gcc.gnu.org/bugzilla/>
  2012-02-27  3:39 ` pinskia at gcc dot gnu.org
@ 2023-06-10  1:56 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-10  1:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
We even miss f3 into f4:
unsigned f3(unsigned a)
{
        long b5 = (a & 0x20)>>5;
        long b3 = (a & 0x08)>>3;
        return b5 ^ b3;
}
unsigned f4(unsigned a)
{
        unsigned b5 = (a ^ (a << 2));
        return (b5>>5)&1;
}

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

* [Bug tree-optimization/32648] missed-optimization: bit-manipulation via bool's
       [not found] <bug-32648-4@http.gcc.gnu.org/bugzilla/>
@ 2012-02-27  3:39 ` pinskia at gcc dot gnu.org
  2023-06-10  1:56 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-27  3:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-27 02:50:36 UTC ---
Right now on the trunk we produce:
    movl    %edi, %edx
    movl    %edi, %eax
    shrl    $3, %edx
    shrl    $5, %eax
    xorl    %edx, %eax
    andl    $1, %eax
    ret

Which is much better than what we produce before.


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

end of thread, other threads:[~2023-06-10  1:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-06 12:25 [Bug c++/32648] New: missed-optimization: bit-manipulation via bool's wouter dot vermaelen at scarlet dot be
2007-07-06 12:54 ` [Bug tree-optimization/32648] " rguenth at gcc dot gnu dot org
2007-07-07  3:10 ` rob1weld at aol dot com
     [not found] <bug-32648-4@http.gcc.gnu.org/bugzilla/>
2012-02-27  3:39 ` pinskia at gcc dot gnu.org
2023-06-10  1:56 ` pinskia 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).