I was plying with some C code to inspect how my compiler (main-git Clang, in this case) handles function parameters wrt to the stack in ARM ABI. I discovered that this function:
int test(int a, int b, int c, int d, int e, int f, int g) {
return a + b + c + d + e + f + g;
}
gets translated, with -O0, in
08000298 <test>:
8000298: b084 sub sp, #16
800029a: f8dd c018 ldr.w ip, [sp, #24]
800029e: f8dd c014 ldr.w ip, [sp, #20]
80002a2: f8dd c010 ldr.w ip, [sp, #16]
80002a6: 9003 str r0, [sp, #12]
80002a8: 9102 str r1, [sp, #8]
80002aa: 9201 str r2, [sp, #4]
80002ac: 9300 str r3, [sp, #0]
80002ae: 9803 ldr r0, [sp, #12]
80002b0: 9902 ldr r1, [sp, #8]
80002b2: 4408 add r0, r1
80002b4: 9901 ldr r1, [sp, #4]
80002b6: 4408 add r0, r1
80002b8: 9900 ldr r1, [sp, #0]
80002ba: 4408 add r0, r1
80002bc: 9904 ldr r1, [sp, #16]
80002be: 4408 add r0, r1
80002c0: 9905 ldr r1, [sp, #20]
80002c2: 4408 add r0, r1
80002c4: 9906 ldr r1, [sp, #24]
80002c6: 4408 add r0, r1
80002c8: b004 add sp, #16
80002ca: 4770 bx lr
Notice the initial store of values in ip. Why are there? They feel useless to me, even with -O0. (-O0 explains why it spills a to d from r0-r3 to the stack on function entry and reloads them later when needed. But these loads of the stack args aren't doing anything.)
I don't understand what's the usage of ip in this case, since it's not used later, and it's not used as a frame pointer (which iiuc is its normal usage?). Thanks!