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

[Bug c++/66520] bad code generated code for branches with single &


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66520

--- Comment #8 from Fisnik <fkastrati at gmail dot com> ---
(In reply to Andreas Schwab from comment #6)
> If a and b are side-effect-free, pure-boolean expressions then `a && b' and
> `a & b' are completely equivalent and there is no reason to generate
> different code for them.

I said it is an optimization bug. 
The branchy code is very expensive when the first operand has probability of
around 0.5 of being true, therefore it ruins the branch prediction. Now you can
imagine a much more complex scenario, such as  e.g. (A & B & ... & Z), and if
all predicates have probabilities of 0.5, then I'll end here with very
inefficient code (the way the g++ is generating assembly). This does not happen
for e.g. with icc.

To this end, the compiler should respect the code written by the developer. I'm
already having trouble with g++, as for the code with single &, it is
generating inefficient code. Or I have to remove completely the optimization
flag '-O3', but then I have a very slow code, and your comments are not helping
me at all solve the problem!


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