This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66520] bad code generated code for branches with single &
- From: "ebotcazou at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 13 Jun 2015 10:13:17 +0000
- Subject: [Bug c++/66520] bad code generated code for branches with single &
- Auto-submitted: auto-generated
- References: <bug-66520-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66520
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |ebotcazou at gcc dot gnu.org
Resolution|--- |WORKSFORME
--- Comment #1 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> consider the following code snippet (c++):
>
> void ampamp(int x, int y) {
> if (x < 3 && y > 10 )
> printf("%d%d", x, y);
> }
>
> void amp(int x, int y) {
> if ((x < 3) & (y > 10) )
> printf("%d%d", x, y);
> }
>
>
> the assembly code generated by g++ (all versions I tested with optimization
> flag `-O3'), is not optimal (see the link on the bottom of this message).
> Basically, for both methods, the generated assembly code is identical.
An optimizing compiler should generate the same code in both cases, either with
or without branches, whatever form is deemed the fastest for the target, since
there are no side-effects involved in the evaluation of the comparisons.
> As a side note: the code by intel's compiler (ICC) is however generating
> optimal code for such scenarios, at least for versions icc13, and icc15 that
> I've tested.
One of the forms is necessarily not optimal (unless they are equivalent).