This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc/1532: Redundant compare instructions on i386
- From: Jamie Lokier <jamie at shareable dot org>
- To: Ian Lance Taylor <ian at wasabisystems dot com>
- Cc: gcc at gcc dot gnu dot org, gcc-bugzilla at gcc dot gnu dot org
- Date: Thu, 22 Jan 2004 03:37:16 +0000
- Subject: Re: gcc/1532: Redundant compare instructions on i386
- References: <m3ptdemh4o.fsf@gossamer.airs.com>
Ian Lance Taylor wrote:
> For a fairly simple test case, found in the PR, gcc generates code
> which looks like this:
>
> cmpl $1, %eax
> je .L1
> cmpl $1, %eax
> jle .L15
>
> The second cmpl instruction is useless. The condition flags will not
> have changed since the first one.
Note that on the original Pentium, the Branch Target Buffer (which is
used to predict branches) cannot store the predicted target of two
branch instructions which are in the same 4 byte address range.
Or something like that.
This means that if "je .L1" is a short branch, the BTB will trash as
it passes through these two instructions, and fail to predict the
branches efficiently. If so, the code is faster with the second cmpl
instruction, although a nop or two is probably better.
-- Jamie