public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/42497]  New: GCC can do less work in the frequently executed path
@ 2009-12-25  8:55 carrot at google dot com
  2009-12-30 17:33 ` [Bug rtl-optimization/42497] Generate conditional tail calls ramana at gcc dot gnu dot org
  2009-12-31 15:33 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: carrot at google dot com @ 2009-12-25  8:55 UTC (permalink / raw)
  To: gcc-bugs

Compile following code with options -march=armv5te -O2

extern void *memcpy(void *dst, const void *src, int n);

void *memmove(void *dst, const void *src, int n)
{
   const char *p = src;
   char *q = dst;
   if (__builtin_expect(q < p, 1)) {
          return memcpy(dst, src, n);
   } else {
          int i=0;
          for (; i<n; i++)
               q[i] = p[i];
   }
   return dst;
}


gcc generates:

memmove:
        cmp     r1, r0              
        str     r4, [sp, #-4]!
        mov     r3, r0
        mov     ip, r1
        mov     r4, r2
        bls     .L8
        ldmfd   sp!, {r4}
        b       memcpy
.L8:
        cmp     r2, #0
        movgt   r2, #0
        ble     .L4
.L5:
        ldrb    r1, [ip, r2]    @ zero_extendqisi2
        strb    r1, [r3, r2]
        add     r2, r2, #1
        cmp     r2, r4
        bne     .L5
.L4:
        mov     r0, r3
        ldmfd   sp!, {r4}
        bx      lr

The if block is expected to be more frequent than the else block, but the
generated code is not very efficient. Better code could be:

        cmp     r1, r0              
        bhi     memcpy
        str     r4, [sp, #-4]!
        mov     r3, r0
        mov     ip, r1
        mov     r4, r2
L8:
        ...


-- 
           Summary: GCC can do less work in the frequently executed path
           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=42497


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

* [Bug rtl-optimization/42497] Generate conditional tail calls .
  2009-12-25  8:55 [Bug target/42497] New: GCC can do less work in the frequently executed path carrot at google dot com
@ 2009-12-30 17:33 ` ramana at gcc dot gnu dot org
  2009-12-31 15:33 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-12-30 17:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ramana at gcc dot gnu dot org  2009-12-30 17:32 -------
The problem here essentially appears to be that GCC can't seem to generate
conditional tail-calls (or conditional calls for that matter in this case) with
-fno-optimize-sibling-calls . I don't read this as a problem with
builtin_expect per-se but that of GCC not being able to generate a conditional
tail-call / call.

A simpler test is essentially the following. 

void foo (int x)
{
  if (x)
    bar ();
  else
    baz ();
}


This is also not just a target problem but probably one for the RTL optimizers
rather any where else..


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
          Component|target                      |rtl-optimization
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-12-30 17:32:59
               date|                            |
            Summary|GCC can do less work in the |Generate conditional tail
                   |frequently executed path    |calls .


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


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

* [Bug rtl-optimization/42497] Generate conditional tail calls .
  2009-12-25  8:55 [Bug target/42497] New: GCC can do less work in the frequently executed path carrot at google dot com
  2009-12-30 17:33 ` [Bug rtl-optimization/42497] Generate conditional tail calls ramana at gcc dot gnu dot org
@ 2009-12-31 15:33 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-12-31 15:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-12-31 15:33 -------
What do you expect with -fno-optimize-sibling-calls ...


-- 


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


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

end of thread, other threads:[~2009-12-31 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-25  8:55 [Bug target/42497] New: GCC can do less work in the frequently executed path carrot at google dot com
2009-12-30 17:33 ` [Bug rtl-optimization/42497] Generate conditional tail calls ramana at gcc dot gnu dot org
2009-12-31 15:33 ` rguenth 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).