http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57536
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> --- Something like this: diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 8b28b61..6d11323 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -23101,21 +23101,32 @@ bool ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align) { rtx addr, scratch1, scratch2, scratch3, scratch4; + bool unroll; + + if (optimize_function_for_size_p (cfun)) + return false; + + unroll = (TARGET_UNROLL_STRLEN + && eoschar == const0_rtx + && optimize > 1 + && !optimize_insn_for_size_p ()); /* The generic case of strlen expander is long. Avoid it's expanding unless TARGET_INLINE_ALL_STRINGOPS. */ - 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)) + if (unroll) + { + if (!TARGET_INLINE_ALL_STRINGOPS + && (!CONST_INT_P (align) || INTVAL (align) < 4)) + return false; + } + else if (!TARGET_INLINE_ALL_STRINGOPS) return false; addr = force_reg (Pmode, XEXP (src, 0)); scratch1 = gen_reg_rtx (Pmode); - if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1 - && !optimize_insn_for_size_p ()) + if (unroll) { /* Well it seems that some optimizer does not combine a call like foo(strlen(bar), strlen(bar));