This is the mail archive of the 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]

Re: Optimization is removing wanted branches

On 30 Aug 2001, Geoff Keating wrote:

> "Smith, Stephen P  (AZ75)" <> writes:
> > Several of us are using gcc 2.95.2-6 (from the cygnus distribution) built as
> > a cross compiler for the powerpc.
> > 
> > The other day one of us noticed that the following code is emitted from cc1
> > without a branch when optimization is turned on.  Is there a way to use
> > optimization (-O1, -O2, -O3) and have the assembly branch instuction in the
> > ouput?
> Why?
> It would be slower, at least in general.

At least in the -Os case, this is wrong. But properly implementing -Os on
PPC is a big project. 

And it would not be necessarily slower (or at least measureably slower for
infrequently executed code). As soon as you have to fetch the code from
memory or even L2 cache, bigger code is often a loss, besides the fact
that using the carry stalls the pipelines while branch prediction will
help executing the correct code path... right at least 50% of the time.

In addition, in a bigger function, the test might be moved far enough
ahead of the branch to greatly reduce the loss due to mispredictions.


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