public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Moritz Strübe" <moritz.struebe@redheads.de>
To: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: __builtin_expect() reduces optimization (Was: GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation)
Date: Wed, 27 Mar 2019 13:37:00 -0000	[thread overview]
Message-ID: <11273fd9-92c0-cbf4-30be-182670ebc823@redheads.de> (raw)
In-Reply-To: <a5b2ed83-128e-a1c8-f40c-3a3556df2678@redheads.de>

Hey.

Am 25.03.2019 um 13:36 schrieb Moritz Strübe:
> I have the following code:
> ----------
> #include <stdint.h>
> #ifdef UN
> #define UNLIKELY(x)     __builtin_expect((x),0)
> #else
> #define UNLIKELY(x) (x)
> #endif
>
> float a = 66;
>
> int test (float b, int test) {
>       if(UNLIKELY(test)) {
>           return b / a;
>       } else {
>           return b * a;
>       }
> }
> ----------
> "gcc -O2" reorders the code depending on a passed -DUN, while -Os always
> produces the same output (seehttps://godbolt.org/z/cL-Pbg)

Actually that is wrong. I was diverted by looking for reorderings. When 
compiling with -Os -DUN there is an additional, and unnecessary, "movaps 
%xmm0, %xmm1". (I seen the same thing on arm, as it is more visible 
there: https://bugs.launchpad.net/gcc-arm-embedded/+bug/1821703)

I also had a quick look at the output of -fdump-rtl-bbro, as suggested 
by Martin, but I'm afraid I'll need a week of digging into the specifics 
before I can interpret it.

Cheers
Morty


-- 
Redheads Ltd. Softwaredienstleistungen
Schillerstr. 14
90409 Nürnberg

Telefon: +49 (0)911 180778-50
E-Mail: moritz.struebe@redheads.de | Web: www.redheads.de

Geschäftsführer: Andreas Hanke
Sitz der Gesellschaft: Lauf
Amtsgericht Nürnberg HRB 22681
Ust-ID: DE 249436843


      parent reply	other threads:[~2019-03-27 13:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 12:36 GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation Moritz Strübe
2019-03-27 12:27 ` Martin Liška
2019-03-28  8:27   ` Richard Biener
2019-03-27 13:37 ` Moritz Strübe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11273fd9-92c0-cbf4-30be-182670ebc823@redheads.de \
    --to=moritz.struebe@redheads.de \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).