<div dir="ltr">I'm going to have to read N4150 before commenting on your second point, but in the meantime, a few questions. In the original proposal, if you have:<div><br></div><div>T A,B;</div><div>void foo(T *restrict a, T* restrict b) {</div><div>  A = *b;</div><div>  *a = A;</div><div>}</div><div><br></div><div>How is this going to be modeled so that B is aliased to *a and *b, but A isn't? What if the references to A are in a call made from foo, which will be inlined later on?</div><div><br></div><div>Also, what if the reference is in a side path, like this:</div><div><br></div><div>T A, B;</div><div>void foo(T *restrict a, T *restrict b, bool c) {</div><div>  T tmp = *b;</div><div>  if (c) {</div><div>    A = tmp;</div><div>  }</div><div>  *a = *b;</div><div>}</div><div><br></div><div>Will you alias A to *a and *b? Seems to me you have to, as foo(&A, &B, false) has well-defined semantics. On the scheme I proposed there is no need, as the exit barrier would separate *a from references to A after the call. Not aliasing A *b will save the reload of *b after the conditional.</div><div><br></div><div>Thanks</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div style="line-height:1.5em;padding-top:10px;margin-top:10px;font-family:sans-serif;font-size:small"><span style="color:rgb(85,85,85);border-width:2px 0px 0px;border-style:solid;border-color:rgb(213,15,37);padding-top:2px;margin-top:2px">Raúl E Silvera |</span><span style="color:rgb(85,85,85);border-width:2px 0px 0px;border-style:solid;border-color:rgb(51,105,232);padding-top:2px;margin-top:2px"> SWE |</span><span style="color:rgb(85,85,85);border-width:2px 0px 0px;border-style:solid;border-color:rgb(0,153,57);padding-top:2px;margin-top:2px"> <a href="mailto:rsilvera@google.com" target="_blank">rsilvera@google.com</a> |</span><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(238,178,17);padding-top:2px;margin-top:2px"><font color="#555555"> </font><font color="#0033bb"><u>408-789-2846</u></font></span></div><br></div></div></div></div>
<br><div class="gmail_quote">On Fri, Nov 21, 2014 at 8:35 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">----- Original Message -----<br>
> From: "Raul Silvera" <<a href="mailto:rsilvera@google.com">rsilvera@google.com</a>><br>
> To: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>><br>
> Cc: "Chandler Carruth" <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>>, "LLVM Developers Mailing List" <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><br>
</span><span class="">> Sent: Tuesday, November 18, 2014 9:09:40 PM<br>
> Subject: Re: [LLVMdev] Upcoming Changes/Additions to Scoped-NoAlias metadata<br>
><br>
</span><div><div class="h5">> I preserve them only weakly... I don't want full barriers; in fact, I<br>
> plan to add InstCombine code to combine calls to @llvm.noalias (it<br>
> will also take a list of scopes, not just one, so this is possible).<br>
> The goal is to have as few barriers as possible.<br>
><br>
><br>
> Good.<br>
><br>
> > > Going further, logically the intrinsic should return a pointer to<br>
> > > a<br>
> > > new object, disjoint from all other live objects. It is not<br>
> > > aliased<br>
> > > to A, and is well defined even if it contains &A because A is not<br>
> > > referenced in the scope.<br>
> ><br>
> > This is essentially what is done, but only for accesses in the<br>
> > scope<br>
> > (or some sub-scope). I don't think the semantics allow for what<br>
> > you're suggesting. The specific language from 6.7.3.1p4 says:<br>
> ><br>
> > [from C]<br>
> > During each execution of B, let L be any lvalue that has &L based<br>
> > on<br>
> > P. If L is used to<br>
> > access the value of the object X that it designates, ...,<br>
> > then the following requirements apply: ... Every other lvalue<br>
> > used to access the value of X shall also have its address based on<br>
> > P.<br>
> > [end from C]<br>
> ><br>
> > Where B is defined in 6.7.3.1p2 to be, essentially, the block in<br>
> > which the relevant declaration appears. And we can really only<br>
> > extrapolate from that to the other access in that block, and not to<br>
> > the containing block.<br>
> ><br>
> ><br>
> > Inside that block<br>
> > (the lifetime of P) , it is safe to assume that X is<br>
> > disjoint from an arbitrary live object<br>
> > A. It if was<br>
> ><br>
> > n't<br>
> > , either:<br>
> > - A is independently referenced inside the block, so there is UB<br>
> > and<br>
> > all bets are off.<br>
> > - A is not independently referenced inside the blo ck,<br>
> > so t here are no pairs of accesses to incorrectly reorder as all<br>
> > accesses to A in<br>
> > the block are done through P. You just need to delimit the block<br>
> > with dataflow barriers<br>
> > , summar iz<br>
> > ing the effect of the block at entry/exit.<br>
><br>
> Okay, I think I agree with you assuming that we put in entry/exit<br>
> barriers to preserve the block boundaries. I'd specifically like to<br>
> avoid that, however.<br>
><br>
> I'm not proposing full code motion barriers, only punctual dataflow<br>
> use/defs to signal entry/exit to the scope.<br>
><br>
><br>
><br>
> Logically, entering the scope transfers the pointed data into a new<br>
> unique block of memory, and puts its address on the restrict<br>
> pointer. Exiting the scope transfers it back. Of course you do not<br>
> want to actually allocate a new object and move the data, but you<br>
> can use these semantics to define the scope entry/exit intrinsics.<br>
> Their contribution to dataflow is only limited to the content of the<br>
> address used to initialize the restricted pointer. These would be<br>
> lighter than the proposed intrinsic as they would not have<br>
> specialized control-flow ​restrictions.<br>
<br>
</div></div>Thanks for explaining, I now understand what you're proposing.<br>
<span class=""><br>
><br>
> This approach makes the restrict attribute effective against all live<br>
> variables without having to examine the extent of the scope to<br>
> collect all references, which is in general impractical.<br>
<br>
</span>I think you've misunderstood this. For restrict-qualified local variables, every memory access within the containing block (which is everything in the function for function argument restrict-qualified pointers) get tagged with the scope. This is trivial to determine.<br>
<span class=""><br>
> It also<br>
> removes the need for scope metadata, as there would be no need to<br>
> name the scopes.<br>
<br>
</span>Indeed.<br>
<span class=""><br>
><br>
><br>
> Anyway, this is just a general alternate design, since you were<br>
> asking for one.<br>
<br>
</span>Yes, and thank you for doing so.<br>
<span class=""><br>
> I'm sure still would take some time/effort to map it<br>
> onto the LLVM framework.<br>
<br>
</span>That does not seem too difficult, the question is really just whether or not it gives us what we need...<br>
<br>
><br>
<br>
So in this scheme, we'd have the following:<br>
<br>
void foo(T * restrict a, T * restrict b) {<br>
  *a = *b;<br>
}<br>
<br>
T * x = ..., *y = ..., *z = ..., *w = ...;<br>
foo(x, y);<br>
foo(z, w);<br>
<br>
become:<br>
<br>
T * x = ..., *y = ..., *z = ..., *w = ...;<br>
<br>
T * a1 = @llvm.noalias.start(x); // model: reads from x (with a general write control dep).<br>
T * b1 = @llvm.noalias.start(y);<br>
*a1 = *b1;<br>
@llvm.noalias.end(a1, x); // model: reads from a1, writes to x.<br>
@llvm.noalias.end(b1, y);<br>
<br>
T * a2 = @llvm.noalias.start(z);<br>
T * b2 = @llvm.noalias.start(w);<br>
*a2 = *b2;<br>
@llvm.noalias.end(a2, z);<br>
@llvm.noalias.end(b2, w);<br>
<br>
This does indeed seem generally equivalent to the original proposal in the sense that the original proposal has an implicit ending barrier at the last relevant derived access, and here we have explicit ending barriers. The advantage is the lack of metadata (and associated implementation complexity). The disadvantage is that we have additional barriers to manage, and these are write barriers on the underlying pointers. It is not clear to me this would make too much difference, so long as we aggressively hoisted the ending barriers to just after the last use based on their 'noalias' operands.<br>
<br>
So this is relatively appealing, and I think would not be a bad way to model C99 restrict (extending the scheme to handle mutually-ambiguous restrict-qualified pointers from aggregates seems straightforward). It does not, however, cover cases where the region of guaranteed disjointness (for lack of a better term) is not continuous. This will come up when implementing a scheme such as that in the current C++ alias-set proposal (N4150). To construct a quick example, imagine that our implementation of std::vector is annotated such that (assuming the standard allocator) each std::vector object's internal storage has a distinct alias set, and we have:<br>
<br>
  std::vector<T> x, y;<br>
  ...<br>
  T * q = &x[0];<br>
<span class="">  for (int i = 0; i < 1600; ++i) {<br>
</span>    x[i] = y[i];<br>
    *q += x[i];<br>
  }<br>
<br>
so here we know that the memory accesses inside the operator[] from x and y don't alias, but the alias-set attribute does not tell us about the relationship between those accesses and the *q. The point of dominance, however, needs to associated with the declaration of x and y (specifically, we want to preserve the dominance over the loop). A start/end barrier scheme localized around the inlined operator[] functions would not do that, and placing start/end barriers around the entire live region of x and y would not be correct. I can, however, represent this using the metadata scheme.<br>
<br>
Thanks again,<br>
Hal<br>
<br>
><br>
><br>
><br>
> Regards,<br>
<div class="HOEnZb"><div class="h5">><br>
><br>
><br>
><br>
<br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</div></div></blockquote></div><br></div>