Do compilers (as a rule, or in particular) optimize repeated function calls?
For example, consider this case.
struct foo {
member_type m;
return_type f() const;
};
Function definition is in one translation unit
return_type foo::f() const {
}
Repeated function calls are in another block
foo bar;
some_other_function_a(bar.f());
some_other_function_b(bar.f());
Will the code be converted to the second translation unit?
foo bar;
const return_type _tmp_bar_f = bar.f();
some_other_function_a(_tmp_bar_f);
some_other_function_b(_tmp_bar_f);
Potentially, computation fcan be expensive, but the return type can be something very small (think of a math function returning double). Do compilers make up? Are there any cases when they do it or not? You can consider a generalized version of this question, and not just for member functions or functions without arguments.
Clarification at the suggestion of @BaummitAugen:
, , , . GCC x86_64 Linux.