This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc/1532: Redundant compare instructions on i386


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]