<div dir="ltr">pm = addrspacecast float addrspace(n)* %pn to float addrspace(m)*<div><br></div><div>If addrspace n and m refers to the same memory, then isDereferenceablePointter(pm) is the same as isDereferenceablePointer(pn). This would be true for OpenCL on CPU. However, if address space n and m are disjoint (like in some GPU), pn in address space n would be undefined in address space m. Once addrspacecast'ed, it would not be able to derive dereferenceablity from the original pointer. My original code segment shows it as well.</div><div><br></div><div>My test case tries to have isDereferenceablePointer(pn) to be true (so created it by alloca on stack, which is always dereferenceable). In this way, isDereferenceablePointer(pn) will be true as the current llvm implemenation assumes isDeferenceablePointer(pn) = isDereferenceablePointer(pn). The test case might be a not very good code, but it is correct.</div><div><br></div><div>"<span style="font-size:12.8000001907349px">Have you tried making addrspacecast not isSafeToSpeculativelyExecute?"</span></div><div><span style="font-size:12.8000001907349px"> isSafeToSpeculativelyExecute() invokes isDeferenceablePointer() to check if it is speculative. So, my patch will make isSafeTospeculativeExecute() to return false.</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">"</span><span style="font-size:12.8000001907349px">but since the testcase can be predicated on the address space your testcase looks broken"</span></div><div><span style="font-size:12.8000001907349px">Could you elaborate on this ? </span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><br></div><div><span style="font-size:12.8000001907349px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 16, 2015 at 4:07 PM, Matt Arsenault <span dir="ltr"><<a href="mailto:Matthew.Arsenault@amd.com" target="_blank">Matthew.Arsenault@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
<div>On 03/15/2015 10:43 PM, Junjie Gu
wrote:<br>
</div>
<blockquote type="cite">
<div lang="x-unicode">
<div dir="ltr">
<div>
<div>Given a pointer, does any addrspacecast affect the
pointer's<br>
dereferenceablity ? For example,<br>
%pm = addrspaacecast float addrspacecast(n)* %pn to
float addrspacecast(m)*<br>
%r = load float addrspace(m)* %pm<br>
In another word. the question is whether the following is
true ?<br>
isDereferenceablePointer(pn) ==
isDereferenceablePointer(pm)<br>
<br>
[Note that the function is defined as<br>
Value.cpp:isDereferenceaablePointer(const Value*, ...)
]<br>
<br>
<br>
The reason I am asking this is that the current LLVM
thinks the answer is yes<br>
(they are the same). But for the following case, it will
make non-speculative<br>
load to be moved out of its guard. For example (assume
that isDereferenceablePointer(p)<br>
is true),<br>
<br>
The following code:<br>
<br>
%pm = addrspaacecast float* %p to float
addrspacecast(m)*<br>
if (p is in addrspace(m))<br>
// BB_then<br>
%r0 = load float, float addrspace(m)* %pm;<br>
else // p is in default addrspace<br>
// BB_else<br>
%r1 = load float, float* p;<br>
%r = phi float [r0, BB_then], [r1, BB_else]<br>
<br>
will be transformed to<br>
<br>
%pm = addrspaacecast float* %p to float
addrspacecast(m)*<br>
%r0 = load float addrspace(m)* %pm;<br>
%r1 = load float* p;<br>
%r = select i1 (p is in adrspace(m)) float %r0, float
%r1<br>
<br>
which is wrong as "%r0 = load float addrspace(m)* %pm"
would be illegal<br>
if (p is in addrspace(m)) is false.<br>
<br>
If we agree that the answer to the above question is no,
then fix<br>
is simple (fix diff is attached). I also have a small test
to show<br>
the problem, simplifyCFG actually does the above
transformation<br>
(to reproduce, use "opt -simplifycfg -S test3.ll -o
tt.ll).<br>
<br>
</div>
<div>Any suggestions/comments ?<br>
</div>
<div><br>
<br>
</div>
thanks<br>
</div>
Junjie<br>
</div>
</div>
</blockquote>
<br>
<br></div></div>
I think the pointer should still be dereferencable once casted, but
since the testcase can be predicated on the address space your
testcase looks broken. Have you tried making addrspacecast not
isSafeToSpeculativelyExecute?<br>
<br>
<br>
<blockquote type="cite">
<div lang="x-unicode">
<div dir="ltr">
<div>
<div><br>
</div>
</div>
</div>
</div>
<br>
<fieldset><legend>fix.diff</legend></fieldset>
<br>
<div style="font-family:-moz-fixed;font-size:12px" lang="x-western">
<pre>Index: Value.cpp
===================================================================
--- Value.cpp (revision 232165)
+++ Value.cpp (working copy)
@@ -574,8 +574,8 @@
return isDereferenceablePointer(RelocateInst.derivedPtr(), DL, Visited);
}
- if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V))
- return isDereferenceablePointer(ASC->getOperand(0), DL, Visited);
+// if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V))
+// return isDereferenceablePointer(ASC->getOperand(0), DL, Visited);
// If we don't know, assume the worst.
return false;
</pre>
</div><span class="">
<br>
<fieldset></fieldset>
<br>
<div style="font-family:-moz-fixed;font-size:12px" lang="x-western">
<pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</div>
</span></blockquote>
<br>
</div>
</blockquote></div><br></div>