public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dean at arctic dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug pending/27971] New: eliminate shift in array[(x>>2)&3] Date: Fri, 09 Jun 2006 06:18:00 -0000 [thread overview] Message-ID: <bug-27971-5748@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2006-06-09 6:10 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-06-09 6:18 dean at arctic dot org [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-27971-5748@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).