Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22306

gcc optimization: Increment on condition

$
0
0

I've noticed that gcc12 does not optimize these two functions to the same code (with -O3):

int x = 0;void f(bool a){    if (a) {++x;    }}void f2(bool a){    x += a;}

Basically no transformation is done. That can be seen here: https://godbolt.org/z/1G3n4fxEK

Optimizing f to the code in f2 seems to be trivial and no jump would be needed anymore. However, I'm curious if there's a reason why this is not done by gcc? Is it somehow still slower or something? I would assume it's never slower and sometimes faster, but I might be wrong.

Thanks


Viewing all articles
Browse latest Browse all 22306

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>