This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
__builtin_expect() reduces optimization (Was: GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation)
- From: Moritz Strübe <moritz dot struebe at redheads dot de>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 27 Mar 2019 13:36:54 +0000
- Subject: __builtin_expect() reduces optimization (Was: GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation)
- References: <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