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
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).