I have following c++ code:
inline int choose(int i){
static constexpr int arr[]={1,3,3,2,4,1,4};
return arr[i];
}
void f(int);
int main(){
for(int i=0;i<5;i++){
f(choose(i));
}
}
When I compile this with g++ 8.2 with option -O3, it produces well-optimized asm code. However, when I change the second line from static constexpr
to constexpr
, which should be semantically the same, it no longer optimizes array access, and produces somewhat inefficient asm code.
Does anyone have any idea why this happens?