<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><br></div></div></div>