public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/40697]  New: inefficient code to extract least bits from an integer value
@ 2009-07-09  9:24 carrot at google dot com
  2009-07-09  9:24 ` [Bug target/40697] " carrot at google dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: carrot at google dot com @ 2009-07-09  9:24 UTC (permalink / raw)
  To: gcc-bugs

Compile following function with options -Os -mthumb -march=armv5te

unsigned get_least_bits(unsigned value)
{
  return value << 9 >> 9;
}

Gcc generates:

        ldr     r3, .L2
        @ sp needed for prologue
        and     r0, r0, r3
        bx      lr
.L3:
        .align  2
.L2:
        .word   8388607

A better code sequence should be:

       lsl   r0, 9
       lsr   r0, 9
       bx    lr

It is smaller (without constant pool) and faster.

This transformation was done very early and we can see it in the first tree
dump shift.c.003t.original. Gcc thinks and with a constant is cheaper than two
shifts. It is not true for this case in thumb ISA. On the other hand if the
constant used to and is small, such as 7, it is definitely cheaper than two
shifts. So which method is better is highly depend on both the constant and the
target ISA. It is difficult to make a correct decision in the TREE level. Maybe
we should define a peephole rule to do it.


-- 
           Summary: inefficient code to extract least bits from an integer
                    value
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carrot at google dot com
 GCC build triplet: i686-linux
  GCC host triplet: i686-linux
GCC target triplet: arm-eabi


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


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

end of thread, other threads:[~2010-03-20 19:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-09  9:24 [Bug target/40697] New: inefficient code to extract least bits from an integer value carrot at google dot com
2009-07-09  9:24 ` [Bug target/40697] " carrot at google dot com
2009-07-09  9:59 ` steven at gcc dot gnu dot org
2009-07-09 10:32 ` ramana at gcc dot gnu dot org
2010-03-16 10:56 ` bernds at codesourcery dot com
2010-03-19 18:41 ` bernds at gcc dot gnu dot org
2010-03-20 19:32 ` ramana 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).