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: Some optimization thoughts (and thanks!)

On Wed, May 02, 2001 at 05:55:47PM -0400, Tom Leete wrote:
> Operator && is a sequence point, and it short-circuits. If (A==N) evaluates
> false, (B==M) must not be evaluated and none of its side-effects occur. IMO
> that includes clobbering the processor flags.

I don't think that clobbering the processor flags is a problem here;
the short-circuit of operator && is a high-level language requirement
and the proposed evaluation is allowed when evaluation of 'B' and 'M'
have no side effects (ie, a volatile variable is involved and/or a
function is called that is not marked with __attribute__((const))).

However, the proposed evaluation should not be done in any other case
but when 'B' and 'M' are registers or constants of course, no speed gain
can be expected anyway otherwise.

As far as I understand it, the proposal is therefore that:

if ((expression) && register/constant == register/constant) ...

is NOT short-circuited; because in the case of comparing two registers
it is faster to actually *do* the compare and get rid of an extra conditional
jump that way.

Carlo Wood <>

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