Compiler optimization/inlining for functions using pointer to locals
I am wondering how "smart" can a production C/C++ compiler be when dealing
with functions passing parameters by "reference"?
int add(int a, int b) { return a + b;}
void add(int * a, int * b, int * c) {* a = *b + *c; }
__attribute__ ((fastcall)) void add(void * p) { *(int *)p = *(int *)(p +
sizeof(int)) + *(int *)(p + sizeof(int) * 2);}
int main() {
int a [3];
a[0] = a[1] + a[2]; // 1
a[0] = add(a[1], a[2]); // 2
add(a + 0, a + 4, a + 8); // 3
add((void *)a); // 4
}
My question is how much every of the three calls (2, 3, 4) can be
optimized to end up being as efficient as the "direct" approach, e.g. 1?
While it is clear that 2 most likely will be perfectly optimized, what
about 3 and even more importantly, case 4?
No comments:
Post a Comment