[LLVMdev] possible addrspacecast problem

Junjie Gu jgu222 at gmail.com
Sun Mar 15 22:43:11 PDT 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150315/11514899/attachment.html>
-------------- next part --------------
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;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test3.ll
Type: application/octet-stream
Size: 1574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150315/11514899/attachment.obj>


More information about the llvm-dev mailing list