<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 31, 2017 at 10:23 AM, Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Piotr,<br>
<br>
On March 31, 2017 at 9:07:42 AM, Piotr Padlewski<br>
<span class="">(<a href="mailto:piotr.padlewski@gmail.com">piotr.padlewski@gmail.com</a>) wrote:<br>
> Hi all,<br>
> I have a question about dereferenceable metadata on load instruction. I<br>
> have a patch (<a href="https://reviews.llvm.org/D31539" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D31539</a>) for LICM that hoists loads<br>
> with !invariant.group.<br>
> The motivation example is devirtualization:<br>
</span>> ...<br>
> [snip]<br>
<span class="">><br>
> On the other hand, after performing my LICM of !invariant.group load, GVN<br>
> hoists the second load and I am not sure why it is legal then.<br>
<br>
</span>I suspect what's going on is that we first canonicalize the loop to:<br>
<br>
if (precondition) {<br>
do {<br>
vptr = load vtable;<br>
fptr = *vptr;<br>
...<br>
} while (backedge_condition);<br>
}<br>
<br>
after which it is safe to transform the program to (modulo aliasing):<br>
<br>
if (precondition) {<br>
vptr = load vtable;<br>
fptr = *vptr;<br>
do {<br>
...<br>
} while (backedge_condition);<br>
}<br>
<br>
since the we moved a load from a ("strongly") postdominating location.<br>
We know that once we were in the preheader we know we're definitely<br>
going to execute the vptr and fptr loads, so they better be<br>
dereferenceable. In other words, we're "exploiting undefined<br>
behavior" here.<br></blockquote><div><br></div><div>Yes, this appears to be exactly the case - dominance tells us they must execute at least once in both situations.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
-- Sanjoy<br>
</font></span></blockquote></div><br></div></div>