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