From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5919 invoked by alias); 15 May 2013 18:08:24 -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 5671 invoked by uid 48); 15 May 2013 18:08:19 -0000 From: "umbricola at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug inline-asm/57299] New: Inline assembly memory dependencies produce spurious loads, register pressure, compilation failures Date: Wed, 15 May 2013 18:08:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-05/txt/msg01057.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D57299 Bug ID: 57299 Summary: Inline assembly memory dependencies produce spurious loads, register pressure, compilation failures Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm Assignee: unassigned at gcc dot gnu.org Reporter: umbricola at gmail dot com Consider this function with an inline assembly statement that takes two poi= nter inputs in named registers and declares that it reads and writes the memory = they point to. void f(char *x, char *y) { register char *p asm("edi") =3D x; register char *q asm("esi") =3D y; asm("" : "=3Dm" (*x), "=3Dm" (*y) : "r" (p), "r" (q), "m" (*x), "m" (*y)); } This function should compile cleanly, and the disassembly should have only = the two instructions to load edi and esi from the stacked function arguments, preceded by the prologue of f() and followed by the epilogue of f(). In fact this function is rejected by gcc -m32 -fPIC -c -o f.o f.c: f.c: In function =E2=80=98f=E2=80=99: f.c:4:3: error: =E2=80=98asm=E2=80=99 operand has impossible constraints asm("" ^ This error is wrong. I am using only two named registers, neither of which= is ebx (which is reserved for the implementation of PIC). There are three general-purpose registers left, not to mention that loading edi and esi from the stack shouldn't need any scratch registers anyway. More strangely, removing any one or more of the four memory inputs and outp= uts causes the function to compile successfully. Memory dependencies should not have any effect on register bindings entering and leaving the inline assemb= ly statement, only on optimizations in surrounding code. Removing the -fPIC option (which frees ebx) also makes the function compile. If I remove one of the memory dependencies and disassemble the generated ob= ject code, I see the two expected loads to edi and esi from the stack followed by three unexpected loads to eax, ecx, and edx from the stack. If I leave all= the memory dependencies and remove -fPIC instead, then all four of eax, ebx, ec= x, and edx get loaded after the asm statement. It appears that gcc can convert memory dependencies of inline assembly statements into useless loads into unrelated general-purpose registers. Th= is action is always inefficient and sometimes spuriously exhausts the general-purpose registers, causing valid code to be rejected. I am running a 64-bit gcc 4.8.0 that I compiled from sources. gcc -v says: Using built-in specs. COLLECT_GCC=3D/home/cmihelic/gcc-4.8.0/install/bin/gcc COLLECT_LTO_WRAPPER=3D/home/cmihelic/gcc-4.8.0/install/libexec/gcc/x86_64-u= nknown-linux-gnu/4.8.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ./configure --prefix=3D/home/cmihelic/gcc-4.8.0/install Thread model: posix gcc version 4.8.0 (GCC)=20 On a different Linux machine I have also tried several 64-bit gcc installat= ions I did not compile myself: versions 4.7.2, 4.5.0, 4.4.5, 4.4.3, 4.1.2, and 3.3.1. They fail similarly, although the error message used to be f.c:4: error: can't find a register in class `GENERAL_REGS' while reloading `asm' Thus this behavior is at least ten years old. >>From gcc-bugs-return-422385-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed May 15 18:11:06 2013 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 8204 invoked by alias); 15 May 2013 18:11:06 -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 Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 8149 invoked by uid 48); 15 May 2013 18:11:02 -0000 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/57287] GCC 4.9.0 fails to build GDB on Ubuntu 12.04 Date: Wed, 15 May 2013 18:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: WAITING 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: component bug_severity 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/msg01058.txt.bz2 Content-length: 353 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57287 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c |middle-end Severity|blocker |normal