From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71979 invoked by alias); 14 Jun 2015 11:34:45 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 67827 invoked by uid 48); 14 Jun 2015 11:34:41 -0000 From: "fkastrati at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/66520] bad code generated code for branches with single & Date: Sun, 14 Jun 2015 11:34:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fkastrati at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: WORKSFORME X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-06/txt/msg01275.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66520 --- Comment #8 from Fisnik --- (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!