This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/50677] New: volatile forces load into register
- From: "marc.glisse at normalesup dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 09 Oct 2011 12:51:31 +0000
- Subject: [Bug rtl-optimization/50677] New: volatile forces load into register
- Auto-submitted: auto-generated
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...)