problem with call clobbered regs

Daniel Bayer daniel.bayer@stud.uni-rostock.de
Wed Feb 11 10:04:00 GMT 2004


Hello,

I'm writing a new backend for gcc. At the moment I have a problem with
call clobbered regs. For a certain input it generates this code:

| ldal    %sr, &__umodqi3
| ldah    %sr, &__umodqi3
| mov     %p3, %fp
| subi    %p3, #4		; calculate address
| sti     %p3, %p2		; store p2 in [p3]
| call    %sr
| [...]
| ldal    %sr, &__udivqi3
| ldah    %sr, &__udivqi3
| call    %sr
| [...]
| ldi     %p2, %p3		; load p2 from [p3]

The problem is that %p3 is clobbered by the call to __umodqi3 and
__udivqi3. At "-O1" correct code is generated. If I additionally
use both -fregmove and -fcaller-saves the code is generated as
shown above.

I did some digging in the code that is enabled by -fcaller-saves. It
seems that insns are generated to save and restore %p2.

It seems that the compiler decides to put some value in the
call clobbered reg %p2. Code is generated to store %p2 to [%fp-4].
After the calls the compiler tries to restore %p2, but it doesn't
recalculate [%fp-4]. It uses %p3 which contained this value before it
was clobbered by the calls.

As I don't know that much about the internals of the compiler I don't
know where to start to debug this. What do you think? Is this a bug in
the gcc core or in my backend? I use gcc-3.3.2 but the same happens
with gcc-3.3.3-20040210.


Daniel



More information about the Gcc mailing list