Re: egcs 1.0.1 miscompiles Linux 2.0.33

Jeffrey A Law
1998-03-04T17:12:10Z

In message <34FBCB0C.42D8AD1C@wtal.de>you write:
> Dear Jeff,
>
> I was a shocked by these misunderstandings. Seems that you never tried
> to use an asm() on an i386 computer.
No, I don't use x86 asms a lot. But I've had the "pleasure" of
working with asms on various machines and developing gcc for about
9 years now. So I have more than a clue about how things are
supposed to work :-)

> What we would like to do is:
>
> - setup register ecx with (-1), esi with (cs).
> - execute run the asm-statements
> - tell gcc that ecx and esi do no longer contain the values (-1) and
> (cs)
>
> What would be the correct way to tell this to gcc if not by inputs and
> clobbers?
As folks have stated, the proper way to do this is to set up matching
input/output operands with the output as an earlyclobber. The manual
needs updating in this regard since it is ambigious.

Any asm which sets up a case where a clobber must match an input
is wrong. Plain and simple, it is wrong.

> come on ... this doesn't touch the problem at the head of this message
> (we need to pass a value that is clobbered.) Unless you recommend
> pushing all passed values on the stack and restoring them before we
> leave the asm(). This would make the asm() statement needless, since it
> would never _optimize_ anything for a certain machine.
Yes it does. By claiming its a dummy output the compiler will not
try to use that register to hold any other values across the asm
statement.

By having the an input match the output, you can pass a value to
the asm in a register.

And finally, the earlyclobber on the output prevents the compiler
from associating any unrelated input with the given output.

This mechanism is designed to do exactly what you want it to do
modulo any bugs.

> Or is the question:
> - is it valid to use a asm() for machine specific optimizations?
>
> Sorry for answering this emotionally but I can't understand why this
> need is not obvious to compiler designers.
The need for the mechanism is obvious, the mechanism currently used
by Linux is wrong.