From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30198 invoked by alias); 9 Oct 2011 12:52:04 -0000 Received: (qmail 30190 invoked by uid 22791); 9 Oct 2011 12:52:03 -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; Sun, 09 Oct 2011 12:51:49 +0000 From: "marc.glisse at normalesup dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/50677] New: volatile forces load into register Date: Sun, 09 Oct 2011 12:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: marc.glisse at normalesup 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-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: 2011-10/txt/msg00644.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50677 Bug #: 50677 Summary: volatile forces load into register Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: marc.glisse@normalesup.org Host: x86_64-linux-gnu Compiling this simple program (-Ofast): void f(int volatile*i){++*i;} produces this code: movl (%rdi), %eax addl $1, %eax movl %eax, (%rdi) (or incl %eax for the central line with -Os). However, if I remove "volatile", I get the nicer: addl $1, (%rdi) (or incl (%rdi) with -Os). The second version seems legal to me even in the volatile case, is that wrong? There might be a relation to this thread: http://gcc.gnu.org/ml/gcc/2011-10/msg00006.html (no volatile there, but a failure to fuse load+add+store) This is particularly noticable because people (wrongly) use volatile for threaded code and the 3 instruction version is likely even more racy than the one with a single instruction. (sorry if the category is wrong, I just picked one with "optimization" in the name...)