Hi, I'm a little confused about the behavior of gcc when the function
is not inlined.

Here is an example code:

int __attribute__((noinline)) foo() {
    return 1;
}

int main() {
    if (foo()) {
        printf("foo() returned 1\n");
    } else {
        printf("foo() returned 0\n");
    }
    return 0;
}

After compiling this via `-O3 -flto`, the else block isn't been
optimized and still exists.

Even it's so obvious that the function will return '1', can't the
compiler see that? Does gcc only get this information by inlining the
function? Or is that what the gcc does?

If so, how to make a change to let gcc get this information then?

Thanks
Hanke Zhang

Reply via email to