On Fri, 2016-02-26 at 20:10 +0100, Torvald Riegel wrote: > On Fri, 2016-02-26 at 11:49 +0100, Richard Biener wrote: > > On Thu, Feb 25, 2016 at 6:33 PM, Torvald Riegel <trie...@redhat.com> wrote: > > > On Wed, 2016-02-24 at 13:14 +0100, Richard Biener wrote: > > >> On Tue, Feb 23, 2016 at 8:38 PM, Torvald Riegel <trie...@redhat.com> > > >> wrote: > > >> > I'd like to know, based on the GCC experience, how important we > > >> > consider > > >> > optimizations that may turn data dependencies of pointers into control > > >> > dependencies. I'm thinking about all optimizations or transformations > > >> > that guess that a pointer might have a specific value, and then create > > >> > (specialized) code that assumes this value that is only executed if the > > >> > pointer actually has this value. For example: > > >> > > > >> > int d[2] = {23, compute_something()}; > > >> > > > >> > int compute(int v) { > > >> > if (likely(v == 23)) return 23; > > >> > else <lots of stuff>; > > >> > } > > >> > > > >> > int bar() { > > >> > int *p = ptr.load(memory_order_consume); > > >> > size_t reveal_that_p_is_in_d = p - d[0]; > > >> > return compute(*p); > > >> > } > > >> > > > >> > Could be transformed to (after inlining compute(), and specializing for > > >> > the likely path): > > >> > > > >> > int bar() { > > >> > int *p = ptr.load(memory_order_consume); > > >> > if (p == d) return 23; > > >> > else <lots of stuff(*p)>; > > >> > } > > >>
[snip] > What about the example I gave above? Is it unrealistic for compilers do > ever do something like this, or is it just unlikely to gain much > performance, or is it just that GCC does not do this today? Modification of d happens-before the mo_consume load in this case, so it's "immutable" data and the this specific example would be okay. Sorry for the noise. However, I find it nontrivial to figure out whether a compiler would _not_ be able to replace a data dependency with a control dependency. Such impossibility results are hard. Yet this is something that users of the new mo_consume proposal would have to do, and I'm not sure we'll end up at a state were this is relatively simple to figure out. If we don't know when a programmer intends to use a dependency, we also cannot warn if there's none.