From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124621 invoked by alias); 12 Mar 2015 13:32:33 -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 124162 invoked by uid 48); 12 Mar 2015 13:32:29 -0000 From: "mattiase at acm dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/65402] New: global register variables miscompiled when unit contains sse4.2 functions Date: Thu, 12 Mar 2015 13:32:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mattiase at acm dot org 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: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-03/txt/msg01310.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65402 Bug ID: 65402 Summary: global register variables miscompiled when unit contains sse4.2 functions Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mattiase at acm dot org The mere presence of a function with the attribute target("sse4.2") is enough for gcc to miscompile other functions with respect to global register variables: ---------------- code below! ----------------- __attribute__((target("sse4.2"))) void F(void) {} register long gr1 asm("r12"); register long gr2 asm("r13"); long G(void); int H(void) { gr1 = G(); /* Any code at all, really. */ return 1; } ----------------- code above! ---------------- The existence of F causes H to save/restore all global register variables in its prologue/epilogue, which of course makes these variables impossible to use inside H. Comment out the definition of F, and the problem disappears. This occurs in GCC 4.9.2 on x86-64 (Linux), with -O0 or -O2. Possible workaround: move the register declarations to above F. This is not always easy (in our case, F is really the stuff in ia32intrin.h that happened to be included from header files that we need for the types in the register variable declarations). Although it's good practice to put the global register declarations at the top of the unit, not doing so shouldn't cause functions below to be miscompiled. This appears to be a regression; the bug is not present in GCC 4.8.1.