This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] RFC: Never gimplify ASM_EXPRs
In article <20030605171518.GF20859@redhat.com> you write:
>On Thu, Jun 05, 2003 at 11:12:36AM -0400, Jason Merrill wrote:
>> Andrew and I discussed this issue at the summit, and agreed (I thought)
>> that the asm should either make the operand an input/output operand or pass
>> in X and do the dereference in the explicit assembly.
>
>Doing the dereference explicitly in the assembly is not
>an option. The syntax for various addressing modes
>varies too widely.
>
>IMO yall should be special-casing memory operands.
Indeed, please do.
Having written more inline assembly than is probably good for me, and
caring more about the end result than most, I can say that it is _very_
common to want to let the compiler choose the addressing mode.
Being forced to put a pointer in a register, and always forcing a
indirect reference with something "(%0)" is a _bad_ idea, and if you
force that, then %m ends up basically being useless in inline assembly.
The whole _point_ of "%m" in inline assembly is to say "I want to access
this memory location". It's very very seldom something silly like "I
want to access the value in this memory location".
And if gimplification breaks that "this memory location" and causes
copying, then gimplification shouldn't be done on asms. Or it should be
done more careully, with the understanding that "m" really should be
equivalent to doing a "&" of the asm argument, and then dereferencing it
inside the asm.
It might make perfect sense, indeed, to enforce that asm arguments that
match a "m" have to be lvalues to make that addressability clear.
Quite frankly, anybody who disagrees with me probably has never used
inline assembly extensively, and doesn't understand what it gets used
for. Inline assembly is not used for reasons of perversity (really,
it's not), it's used to do things that the compiler cannot do natively.
So when you access a memory location, you're doing something MAGICAL to
that memory location as far as the compiler is concerned, and if the
compiler decides to access it on its own, then the compiler is BROKEN,
since it makes the inline asm pointless.
Example of magical accesses where you _have_ to use inline assembly:
special atomic operations different from the regular ones ("load with
lock", for example). Or memory-mapped IO that requires special care and
special instructions to access safely ("load from #io"). Or memory
locations used for synchronization, or any number of things - where the
address is as important as the data.
Sure, you could say "use builtins, not inline asm", but that is a hell
of a lot less flexible, and would require gcc to have a built-in for
every conceivable sequence of instructions that makes sense. Which is
just silly, since inline asm is a lot more flexible and powerful anyway.
Linus