[PATCH] D32423: Constant fold barriers of null and undef

Piotr Padlewski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 20 02:48:25 PDT 2017


Prazek added inline comments.


================
Comment at: lib/Analysis/ConstantFolding.cpp:1779-1783
+    if (isa<ConstantPointerNull>(Operands[0])) {
+      if (IntrinsicID == Intrinsic::invariant_group_barrier)
         return Operands[0];
       return nullptr;
     }
----------------
davide wrote:
> Prazek wrote:
> > majnemer wrote:
> > > Isn't this only valid if the address space is zero?
> > True, but can you pass pointer from another addrspace to invariant.group.barrier?
> > 
> > When I try
> >   %X = addrspacecast i8* null to i8 addrspace(1)*
> >   %b2 = call i8* @llvm.invariant.group.barrier(i8* %X)
> > 
> > I get
> >    error: '%X' defined with type 'i8 addrspace(1)*'
> > 
> > I could add this line:
> >   cast<PointerType>(Operands[0]->getType())->getAddressSpace() == 0
> > but I won't be able to test it in any way if I am not wrong.
> > 
> Not positive about this, but does it work if you do:
> 
> ```
>   %b2 = call i8* @llvm.invariant.group.barrier(i8* addrspace(4)* @global0)   
> ```
> 
> where
> 
> ```
> @global0 = addrspace(4) constant i8* null 
> ```
Thanks for help Davide, but it still doesn't work for me. I get the following error:

  error: '@llvm.invariant.group.barrier' defined with type 'i8* (i8*)*'
    %b = call i8* @llvm.invariant.group.barrier(i8* addrspace(4)* @global0)
                  ^

the code looks like this
  @global0 = addrspace(4) constant i8* null

  define i8* @differentAddrspace() {
    %b = call i8* @llvm.invariant.group.barrier(i8* addrspace(4)* @global0)
    ret i8* %b
  }

  declare i8* @llvm.invariant.group.barrier(i8*)


https://reviews.llvm.org/D32423





More information about the llvm-commits mailing list