From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29442 invoked by alias); 15 May 2013 21:57:50 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 29368 invoked by uid 48); 15 May 2013 21:57:44 -0000 From: "umbricola at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: inline-asm X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: umbricola at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-05/txt/msg01074.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57299 --- Comment #8 from Chris Mihelich --- (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 : 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.