public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation
@ 2019-03-25 12:36 Moritz Strübe
  2019-03-27 12:27 ` Martin Liška
  2019-03-27 13:37 ` __builtin_expect() reduces optimization (Was: GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation) Moritz Strübe
  0 siblings, 2 replies; 4+ messages in thread
From: Moritz Strübe @ 2019-03-25 12:36 UTC (permalink / raw)
  To: gcc

Hi,

I have an issue with the optimization options. We are on an stm32 and it 
only has a prefetcher, but no cache. Thus it's nice to have linear 
default path. For example, we use  __builtin_expect in our asserts. Yet 
it seems that this does not work when using -Os. I confirmed that this 
is not an arm issue, but can also be seen on x86.
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 (see https://godbolt.org/z/cL-Pbg)

I played around with different options running
gcc -O{s|2} -Q  --help=optimizers
, but didn't manage to get -Os to do that optimization.
Opposed to what the manual[1] says, this only differs in 
-finline-functions and -foptimize-strlen for 8.3
(OT: Especially the info about freorder-blocks-algorithm seems to be 
outdated for gcc 8.3 (my arm 7.3.1 produces smaller code using stc, too).)
Since adjusting all those options didn't help I tried
gcc -O{s|2} -Q  --help={param|common|target|c++}
but that didn't give me any new insight. (BTW: "-Q --help=param" should 
probably be documented in the --param-section)

Cheers
Moritz


[1] https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Optimize-Options.html

-- 
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-28  8:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` __builtin_expect() reduces optimization (Was: GCC-Reordering-Optimization-Options in Os and O2 when using __builtin_expect() and documentation) Moritz Strübe

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).