From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5002 invoked by alias); 9 Mar 2013 01:54:50 -0000 Received: (qmail 3219 invoked by uid 48); 9 Mar 2013 01:54:23 -0000 From: "dhazeghi at yahoo dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/56576] New: wrong code for aliased union at -O3 Date: Sat, 09 Mar 2013 01:54: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: X-Bugzilla-Severity: normal X-Bugzilla-Who: dhazeghi at yahoo 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-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: 2013-03/txt/msg00723.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56576 Bug #: 56576 Summary: wrong code for aliased union at -O3 Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: dhazeghi@yahoo.com The following code behaves differently at -O3 than at -O2 or below on 4.7 and mainline on x86_64-linux. At -O3 it returns 1, whereas at -O2 and below it returns 0, for both -m32 and -m64 targets. It behaves as expected on gcc 4.6 at all optimization levels (returns 0). $ gcc-trunk --version gcc-trunk (GCC) 4.8.0 20130308 (experimental) [trunk revision 196555] $ gcc-trunk -O2 trans-reduced.c $ ./a.out $ echo $? 0 $ gcc-trunk -O3 trans-reduced.c $ ./a.out $ echo $? 1 $ gcc-4.6 -O3 trans-reduced.c $ ./a.out $ echo $? 0 $ cat trans-reduced.c /* gcc-4.7/gcc-trunk -O3 -m32/-m64 */ union { int f0; int f1; long f2; } a, b; int c, h; int *d, *e = &a.f0; long *f = &b.f2; int **g = &d; void fn1 () { c = 0; for (; c <= 3; c++) { int *i = &b.f1; *f = 1; *i = 0; *g = 0; h = *e; } } int main () { fn1 (); return b.f0; }