This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/32650] New: Convert p+strlen(p) to strchr(p, '\0') if profitable


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]