This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/32650] New: Convert p+strlen(p) to strchr(p, '\0') if profitable
- From: "kazu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jul 2007 15:53:22 -0000
- Subject: [Bug tree-optimization/32650] New: Convert p+strlen(p) to strchr(p, '\0') if profitable
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
According to Mark Mitchell, strchr(p,'\0') is more efficient than
p+strlen(p).
#include <string.h>
void * f (char *p) { return p + strlen (p); }
void * g (char *p) { return strchr (p, '\0'); }
g:
xorl %esi, %esi
jmp __rawmemchr
f:
pushq %rbx
movq %rdi, %rbx
call strlen
leaq (%rbx,%rax), %rax
popq %rbx
ret
--
Summary: Convert p+strlen(p) to strchr(p, '\0') if profitable
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kazu at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32650