public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bobby.prani at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/63375] [4.8/4.9/5 Regression] reordering of reads across fences Date: Mon, 24 Nov 2014 15:03:00 -0000 [thread overview] Message-ID: <bug-63375-4-tjwKOzw59A@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-63375-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63375 --- Comment #13 from Pranith Kumar <bobby.prani at gmail dot com> --- The main concern here is moving the read past the fence instruction irrespective of volatile semantics. The fence instruction guarantees that accesses before the fence will complete before the accesses coming after the fence. Consider the following case: #include<stdio.h> typedef struct { int counter; } atomic_t; static inline int atomic_read(atomic_t *v) { return (*(volatile int *)&(v)->counter); } static inline void atomic_write(atomic_t *v, int val) { v->counter = val; } #define smp_mb() asm volatile ("mfence":::"memory") atomic_t val2 = {1}; int main() { atomic_t val1 = {1}; int p, q; smp_mb(); p = atomic_read(&val1); smp_mb(); atomic_write(&val2, 2); smp_mb(); q = atomic_read(&val2); printf("%d %d\n", p, q); return 0; } Here, because of the bug the read from val1 is being generated after the write to val2 breaking the semantics of memory fences. What am I missing?
next prev parent reply other threads:[~2014-11-24 15:03 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-09-25 23:08 [Bug rtl-optimization/63375] New: " bobby.prani at gmail dot com 2014-09-25 23:11 ` [Bug rtl-optimization/63375] " bobby.prani at gmail dot com 2014-09-26 0:35 ` [Bug tree-optimization/63375] " pinskia at gcc dot gnu.org 2014-09-26 8:18 ` [Bug tree-optimization/63375] [4.8/4.9/5 Regression] " rguenth at gcc dot gnu.org 2014-10-01 14:49 ` jamborm at gcc dot gnu.org 2014-10-02 16:49 ` jamborm at gcc dot gnu.org 2014-10-02 17:12 ` jamborm at gcc dot gnu.org 2014-10-02 17:14 ` jamborm at gcc dot gnu.org 2014-10-09 9:04 ` jakub at gcc dot gnu.org 2014-10-10 11:13 ` rguenth at gcc dot gnu.org 2014-11-10 17:34 ` [Bug rtl-optimization/63375] " bobby.prani at gmail dot com 2014-11-24 13:34 ` rguenth at gcc dot gnu.org 2014-11-24 15:03 ` bobby.prani at gmail dot com [this message] 2014-11-24 15:19 ` jakub at gcc dot gnu.org 2014-11-24 16:12 ` rguenth at gcc dot gnu.org 2014-11-24 19:32 ` bobby.prani at gmail dot com 2014-11-25 10:15 ` mikpelinux at gmail dot com
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-63375-4-tjwKOzw59A@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).