This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about usage of r12 (ip) on ARM


On 29/08/16 08:52, Fredrik Hederstierna wrote:
> 
>>> Couldn't this be compiled to as the following, with using r12 'ip':
>>>
>>> 00000000 <test>:
>>> 0: xxxxxxxx push {r4, lr}
>>> 4: xxxxxxxx mov r4, r0
>>> 8: xxxxxxxx ldr ip, [r0]
>>> c: xxxxxxxx bl 0 <func>
>>> 10: xxxxxxxx str ip, [r4]
>>> 14: xxxxxxxx pop {r4, pc}
>>>
>>
>> No. IP cna be clobbered either by func itself or any
>> inter-procedural
>> veneer that might be generated by the linker. You'd need to prove
>> that
>> neither could happen before IP could be used to hold a value over a
>> function call.
>>
>> R.
> 
> Ah, yes of course you are right, my mistake.
> 
> Meaning also that r1-r3 which be used as unsused arguments/scratch in this case cannot be used either,
> since inner function calls are not obliged to restore them according to AAPCS.
> I think I got confused by the dummy register pushes added to keep stack alignment.
> 

In general yes.   in a small number of cases, when we know that 'func'
cannot be preempted at link time by another definition and when we know
that some of r0-r3 are not used by func, then we can use those as
cheaper callee-saved alternatives, but it's quite rare.

R.

> Thanks!
> BR Fredrik
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]