public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "umbricola at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug inline-asm/57299] Inline assembly memory dependencies produce spurious loads, register pressure, compilation failures
Date: Wed, 15 May 2013 21:57:00 -0000	[thread overview]
Message-ID: <bug-57299-4-HHpX7el052@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57299-4@http.gcc.gnu.org/bugzilla/>

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.


  parent reply	other threads:[~2013-05-15 21:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-15 18:08 [Bug inline-asm/57299] New: " umbricola at gmail dot com
2013-05-15 18:14 ` [Bug inline-asm/57299] " pinskia at gcc dot gnu.org
2013-05-15 18:22 ` umbricola at gmail dot com
2013-05-15 18:24 ` pinskia at gcc dot gnu.org
2013-05-15 18:44 ` umbricola at gmail dot com
2013-05-15 18:53 ` pinskia at gcc dot gnu.org
2013-05-15 19:20 ` umbricola at gmail dot com
2013-05-15 20:16 ` pinskia at gcc dot gnu.org
2013-05-15 21:57 ` umbricola at gmail dot com [this message]
2013-05-15 21:59 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-57299-4-HHpX7el052@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).