https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95769
Bug ID: 95769 Summary: Constant expression in inline function not optimized Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gcc at mailinator dot com Target Milestone: --- Godbolt link: https://godbolt.org/z/Kimna8 Code: ``` int constexpr expensive_function(int x){ int result{}; while(x!=1){ x=x%2!=0 ? x*3+1 : x/2; result++; } return result; } int constexpr other_function(int a, int b){ return a*expensive_function(b); } int f_(int x){ return other_function(x, 1000); } int g(int x){ return x*expensive_function(1000); } ``` The function `g` is optimized so `expensive_function(1000)` is evaluated at compile time. The function `f` isn't.