http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57299

--- Comment #8 from Chris Mihelich <umbricola at gmail dot com> ---
(In reply to Andrew Pinski from comment #7)
> Actually it only needs 4 (and not 6) due to holding of the pointer of y and
> x can happen with only 2 registers.

That's not what GCC is doing, actually.  When I take out -fPIC and compile, the
disassembly looks like this:

00000000 <f>:
   0:    55                       push   %ebp
   1:    89 e5                    mov    %esp,%ebp
   3:    57                       push   %edi
   4:    56                       push   %esi
   5:    53                       push   %ebx
   6:    8b 7d 08                 mov    0x8(%ebp),%edi
   9:    8b 75 0c                 mov    0xc(%ebp),%esi
   c:    8b 45 08                 mov    0x8(%ebp),%eax
   f:    8b 5d 0c                 mov    0xc(%ebp),%ebx
  12:    8b 55 08                 mov    0x8(%ebp),%edx
  15:    8b 4d 0c                 mov    0xc(%ebp),%ecx
  18:    5b                       pop    %ebx
  19:    5e                       pop    %esi
  1a:    5f                       pop    %edi
  1b:    5d                       pop    %ebp
  1c:    c3                       ret    

You can see that six registers, not four, are being loaded in the body of f.

> And you can use the operands of the m inside the inline-asm which is why it
> needs to store the pointer in a register.

If I gave the "m" operand a name and used the name, or if I referred to, say,
%0 inside the body of the asm statement, you would be correct.  But I didn't. 
There is no reason to give a register to a "m" or "=m" operand that is not
referenced in the asm body, and this is the common case for "m" operands. 
Their main purpose is to prevent incorrect optimizations, not to pass values to
the assembly code.

The spurious register allocation makes "m" operands unusable in most complex
asm statements.  It doesn't take too many memory dependencies to exhaust the
stingy x86 general-purpose register set.

Reply via email to