[LLVMdev] possible addrspacecast problem

Matt Arsenault Matthew.Arsenault at amd.com
Mon Mar 16 16:07:44 PDT 2015


On 03/15/2015 10:43 PM, Junjie Gu wrote:
> Given a pointer,  does any addrspacecast affect the pointer's
> dereferenceablity ?  For example,
>     %pm = addrspaacecast float addrspacecast(n)* %pn to float 
> addrspacecast(m)*
>     %r  = load float addrspace(m)* %pm
> In another word. the question is whether the following is true ?
>     isDereferenceablePointer(pn) == isDereferenceablePointer(pm)
>
>   [Note that the function is defined as
>    Value.cpp:isDereferenceaablePointer(const Value*, ...) ]
>
>
> The reason I am asking this is that the current LLVM thinks the answer 
> is yes
> (they are the same).  But for the following case, it will make 
> non-speculative
> load to be moved out of its guard.  For example (assume that 
> isDereferenceablePointer(p)
> is true),
>
> The following code:
>
>      %pm = addrspaacecast float* %p to float addrspacecast(m)*
>      if (p is in addrspace(m))
>         // BB_then
>         %r0 = load float,  float addrspace(m)* %pm;
>      else  // p is in default addrspace
>         // BB_else
>         %r1 = load float,  float* p;
>      %r = phi float [r0, BB_then], [r1, BB_else]
>
> will be transformed to
>
>      %pm = addrspaacecast float* %p to float addrspacecast(m)*
>      %r0 = load float addrspace(m)* %pm;
>      %r1 = load float* p;
>      %r = select i1 (p is in adrspace(m)) float %r0, float %r1
>
> which is wrong as "%r0 = load float addrspace(m)* %pm" would be illegal
> if (p is in addrspace(m)) is false.
>
> If we agree that the answer to the above question is no, then fix
> is simple (fix diff is attached). I also have a small test to show
> the problem,  simplifyCFG actually does the above transformation
> (to reproduce, use "opt -simplifycfg -S test3.ll -o tt.ll).
>
> Any suggestions/comments ?
>
>
> thanks
> Junjie


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?


>
>
> fix.diff
>
>
> 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;
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu          http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150316/2d1aabd5/attachment.html>


More information about the llvm-dev mailing list