From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3721 invoked by alias); 24 Jan 2012 22:31:58 -0000 Received: (qmail 3711 invoked by uid 22791); 24 Jan 2012 22:31:57 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 Jan 2012 22:31:45 +0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/51987] New: [4.7 Regression] Predictive commoning wrong-code with non-volatile asm Date: Tue, 24 Jan 2012 22:41:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-01/txt/msg02833.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51987 Bug #: 51987 Summary: [4.7 Regression] Predictive commoning wrong-code with non-volatile asm Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization AssignedTo: jakub@gcc.gnu.org ReportedBy: jakub@gcc.gnu.org On s390 (31-bit) gcc 4.7 miscompiles _itoa.o and _itoa.os in glibc (which leads to e.g. cc1 itself when using that glibc to crash on startup). Here is a reduced testcase (for x86_64): extern void abort (void); union U { unsigned long l; struct { unsigned int l, h; } i; }; __attribute__((noinline, noclone)) void foo (char *x, char *y) { int i; for (i = 0; i < 64; i++) { union U u; asm ("movl %1, %k0; salq $32, %0" : "=r" (u.l) : "r" (i)); x[i] = u.i.h; union U v; asm ("movl %1, %k0; salq $32, %0" : "=r" (v.l) : "r" (i)); y[i] = v.i.h; } } int main () { char a[64], b[64]; int i; foo (a, b); for (i = 0; i < 64; i++) if (a[i] != i || b[i] != i) abort (); return 0; } This is miscompiled at -O3, predictive commoning ignores the references in the inline-asm and happily moves loads of u.i.h and v.i.h before the loop, even when it is initialized only by the inline asm inside of the loop. The problem is that tree-data-ref.c (get_references_in_stmt) gives up on GIMPLE_ASM only if it is volatile, and for non-volatile GIMPLE_ASM it just (incorrectly) assumes it doesn't have any references.