public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "us15 at os dot inf.tu-dresden.de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/47698] New: CMOV accessing volatile memory with read side effect Date: Fri, 11 Feb 2011 15:40:00 -0000 [thread overview] Message-ID: <bug-47698-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47698 Summary: CMOV accessing volatile memory with read side effect Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: us15@os.inf.tu-dresden.de In the attached testcase, the variable "mmio" is a memory-mapped device register with read side effects. It must only be accessed if "cond" is true. When compiling the testcase: gcc -Os -c testcase.cc -o testcase.o the following output is generated: 0000000000000000 <foo()>: 0: 31 c0 xor %eax,%eax 2: 48 83 3d 00 00 00 00 cmpq $0x0,0x0(%rip) # a <foo()+0xa> 9: 00 a: 48 0f 45 05 00 00 00 cmovne 0x0(%rip),%rax # 12 <foo()+0x12> 11: 00 12: c3 retq Due to the use of CMOV, gcc is reading the memory location regardless of "cond" being true, even though "mmio" is casted to volatile. Reading "mmio" through a volatile pointer, as in return *static_cast<volatile unsigned long *>(&mmio); does not get rid of the CMOV either. What is the correct way to ensure mmio is read if and only if cond is true? My gcc version is: gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-slackware-linux/4.6.0/lto-wrapper Target: x86_64-slackware-linux Configured with: ../gcc-svn/configure --prefix=/usr --libdir=/usr/lib64 --mandir=/usr/man --infodir=/usr/info --enable-shared --enable-bootstrap --enable-languages=c,c++,lto --enable-threads=posix --enable-checking=release --with-system-zlib --with-python-dir=/lib64/python2.6/site-packages --disable-libunwind-exceptions --enable-__cxa_atexit --enable-libssp --enable-lto --with-gnu-ld --verbose --disable-multilib --target=x86_64-slackware-linux --build=x86_64-slackware-linux --host=x86_64-slackware-linux Thread model: posix gcc version 4.6.0 20110211 (experimental) (GCC)
next reply other threads:[~2011-02-11 15:40 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-02-11 15:40 us15 at os dot inf.tu-dresden.de [this message] 2011-02-11 15:43 ` [Bug rtl-optimization/47698] " us15 at os dot inf.tu-dresden.de 2011-02-11 16:04 ` us15 at os dot inf.tu-dresden.de 2011-02-11 16:36 ` rguenth at gcc dot gnu.org 2011-02-11 17:07 ` matz at gcc dot gnu.org 2011-02-11 17:57 ` hjl.tools at gmail dot com 2011-11-07 8:42 ` kyukhin at gcc dot gnu.org 2011-11-08 13:46 ` ebotcazou at gcc dot gnu.org 2012-01-21 20:27 ` pinskia at gcc dot gnu.org 2021-07-29 22:34 ` pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-47698-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).