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

__builtin_expect() reduces optimization (Was: GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation)


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


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