[PATCH][stage1] Prefer to use strlen call instead of inline expansion (PR target/88809).

Alexander Monakov amonakov@ispras.ru
Fri Apr 26 08:53:00 GMT 2019


On Fri, 26 Apr 2019, Martin Liška wrote:

> I'm suggesting to adjust that to:
> - -Os will keep using rep-scasb as -Os means optimize for size
>  no matter what speed impact is

I'm not sure it's a good choice, the inline sequence is

        xorl    %eax, %eax
        orq     $-1, %rcx
        repnz scasb
        notq    %rcx
        decq    %rcx

compared to simply

	call	strlen

it's not even shorter.

> - otherwise use call to strlen
> - when -minline-all-stringops is enabled and -O2+ is used, then
>   expand to 4B loop for all possible alignments

But it's not OK to use misaligned loads, because overreading past
end of string may cross a page boundary and cause a segfault. What does
your patch generate for the testcase at -O2 -minline-all-stringops?

Alexander


More information about the Gcc-patches mailing list