Subject: Re: gcc de-optimisations
To: None <>
From: Ian Lance Taylor <>
List: tech-toolchain
Date: 10/23/2005 21:13:56
Alan Barrett <> writes:

> On Sun, 23 Oct 2005, David Laight wrote:
> > How do we stop gcc (i386) converting:
> >     if (memcmp(a, b, 16))
> > into:
> >     movl  %ecx, #16
> >     repeq cmpsb
> CFLAGS += -fno-builtin-memcmp

That isn't an ideal solution, as it will prevent gcc from expanding
memcmp in any other way.

Another non-ideal solution is to compile with -Os.

> I suppose a real fix would somehow make gcc choose between the
> function call or the string operation based on various optimisation
> flags and detailed knowledge of the performance characteristics
> of the target CPU, but such a thing is far beyond my skill.  The
> relevant code is the (define_expand "cmpstrsi" ...) part of
> src/gnu/dist/gcc/gcc/config/i386/, along with tests for
> HAVE_cmpstrsi in src/gnu/dist/gcc/gcc/builtins.c.

Yes.  Some of these expansions are chosen by the processor type (see
uses of TARGET_SINGLE_STRINGOP.  For some reason memcmp isn't one of
them.  It would be appropriate to file a bug report at