public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug pending/27971]  New: eliminate shift in array[(x>>2)&3]
@ 2006-06-09  6:18 dean at arctic dot org
  2006-06-09  6:20 ` [Bug target/27971] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: dean at arctic dot org @ 2006-06-09  6:18 UTC (permalink / raw)
  To: gcc-bugs

array[(x>>2)&3] can be arranged to avoid the right shift.

consider:

% cat shift-and-fold.c
unsigned array[4];

unsigned foo(unsigned long x)
{
          return array[(x>>2)&3ul];
}
% /home/odo/gcc/bin/gcc -g -O3 -Wall   -c -o shift-and-fold.o shift-and-fold.c
% objdump -dr shift-and-fold.o

shift-and-fold.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <foo>:
   0:   48 c1 ef 02             shr    $0x2,%rdi
   4:   83 e7 03                and    $0x3,%edi
   7:   8b 04 bd 00 00 00 00    mov    0x0(,%rdi,4),%eax
                        a: R_X86_64_32S array
   e:   c3                      retq

could be:

  and $0xc,%edi
  mov 0(%rdi),%eax

gcc does the right thing when the left shift isn't part of an address...

thanks
-dean

% /home/odo/gcc/bin/gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../gcc/configure --prefix=/home/odo/gcc
--host=x86_64-linux-gnu --disable-multilib --enable-languages=c,c++
--disable-bootstrap
Thread model: posix
gcc version 4.2.0 20060603 (experimental)


-- 
           Summary: eliminate shift in array[(x>>2)&3]
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: pending
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dean at arctic dot org
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


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


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

end of thread, other threads:[~2008-01-14 19:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-09  6:18 [Bug pending/27971] New: eliminate shift in array[(x>>2)&3] dean at arctic dot org
2006-06-09  6:20 ` [Bug target/27971] " pinskia at gcc dot gnu dot org
2006-06-09  6:43 ` pinskia at gcc dot gnu dot org
2007-11-28 23:06 ` raksit at google dot com
2007-12-05 19:28 ` raksit at google dot com
2008-01-11  4:51 ` raksit at gcc dot gnu dot org
2008-01-14 19:57 ` raksit 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).