[Bug target/103882] Register corruption in ASM only functions when optization is -O2/-Os/-O3

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Jan 1 14:05:09 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103882

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jose Silva from comment #6)
> Yes, noipa does help.
> 
> (In reply to Andrew Pinski from comment #3)
> > Oh that is because there is some IPA Register allocation going on. Anyways
> > this is still not a bug. You need to mark a0 as a clobber in the inline-asm
> > to let GCC know that a0 is touched.
> 
> As I said I simplified the example, the original code had a syscall which I
> have no idea which registers will be clobbered.

The compiler has no idea either (it has intentionally no idea what the inline
asm does, it is a black box to the compiler), so that is why you need to
specify it.  Look at C library sources, or kernel and find out what is and what
isn't clobbered and add the clobbers.

> I'm quite confused on why you say "Anyways this is still not a bug". IPA RA
> is making assumptions on procedures where it does not have enough
> information to do so, i.e functions with asm statements. It is disabled when
> a function pointer is used, why shouldn't it be for when a function with ASM
> statement is encountered?

Inline asms need to tell the compiler what registers they are setting, which
they are using and what they are clobbering, otherwise the shouldn't set, use
or clobber anything...  You can still e.g. save and restore the registers
yourself in the inline asm...


More information about the Gcc-bugs mailing list