<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr">On Sat, Dec 8, 2012 at 5:39 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div dir="ltr">
<div class="im">On Sat, Dec 8, 2012 at 5:09 PM, Joerg Sonnenberger <span dir="ltr"><<a href="mailto:joerg@britannica.bec.de" target="_blank">joerg@britannica.bec.de</a>></span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
consider the following input:<br>
<br>
int y;<br>
<br>
void foo(int * restrict x)<br>
{<br>
        if (x == &y)<br>
                (*x)++;<br>
        (*x)++;<br>
}<br>
<br>
The clang codegen gives the argument of foo the noalias attribute and<br>
GVN will optimise the condition to false.<br>
<br>
When discussing this on IRC, Chandler suggested that Clang shouldn't be<br>
creating the noalias attribute here, i.e. do alias interference. I'm not<br>
sure he is correct, but this is subtle enough to warrant some discussion<br>
before filling a PR.<br></blockquote><div><br></div></div><div>Sorry, I was wrong. On further consideration, I think Clang is correct here.</div><div><br></div><div>1) (*x) is an lvalue based on the pointer 'x' and is modified in the function, so the restrict qualifier actually governs the set of addresses viable...</div>

<div>2) The expression 'y' is an lvalue expression AFAICT in the C99 standard, is not based on the pointer 'x', and thus cannot access the same object which x points to.</div><div><br></div><div>
Thus, clang is correct to optimize the condition to false I think...</div></div></div></div></div>
</blockquote></div><br></div><div class="gmail_extra" style>As Joerg pointed out in IRC, 'y' is an lvalue, but we do not use it to access the object it designates, we only use it to compute the address, and thus restrict should have no bearing on it. That would in turn make Clang's optimization incorrect and also seems likely to make 'noalias' essentially useless for modeling restrict. =/</div>
</div></div>