http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57536
Bug ID: 57536 Summary: Inconsistent behavior of strlen inline and unroll Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: uros at gcc dot gnu.org Target: i386 There is /* X86_TUNE_UNROLL_STRLEN */ m_486 | m_PENT | m_PPRO | m_ATOM | m_CORE_ALL | m_K6 | m_AMD_MULTIPLE | m_GENERIC, ix86_expand_strlen has if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1 && !TARGET_INLINE_ALL_STRINGOPS && !optimize_insn_for_size_p () && (!CONST_INT_P (align) || INTVAL (align) < 4)) return false; The decision depends on both TARGET_UNROLL_STRLEN and TARGET_INLINE_ALL_STRINGOPS. If both TARGET_UNROLL_STRLEN and TARGET_INLINE_ALL_STRINGOPS are false, strlen is inlined: [hjl@gnu-6 gcc]$ cat x.i int strlen (const char *); int foo (const char *s) { return strlen (s); } [hjl@gnu-6 gcc]$ gcc -S -m32 -O2 x.i -mno-inline-all-stringops -mtune=i386 [hjl@gnu-6 gcc]$ cat x.s .file "x.i" .text .p2align 2,,3 .globl foo .type foo, @function foo: .LFB0: .cfi_startproc pushl %edi .cfi_def_cfa_offset 8 .cfi_offset 7, -8 movl 8(%esp), %edi xorl %eax, %eax movl $-1, %ecx repnz scasb notl %ecx leal -1(%ecx), %eax popl %edi .cfi_restore 7 .cfi_def_cfa_offset 4 ret [hjl@gnu-6 gcc]$ gcc -S -m32 -O2 x.i -mno-inline-all-stringops -mtune=i486 [hjl@gnu-6 gcc]$ cat x.s .file "x.i" .text .p2align 4,,15 .globl foo .type foo, @function foo: .LFB0: .cfi_startproc jmp strlen