[PATCH] D44985: [CUDA] Let device-side shared variables be initialized with undef

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 2 09:51:15 PDT 2018


yaxunl added inline comments.


================
Comment at: lib/CodeGen/CGDecl.cpp:235-240
+  if (Ty.getAddressSpace() != LangAS::opencl_local &&
+      !(getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
+        D.hasAttr<CUDASharedAttr>()))
     Init = EmitNullConstant(Ty);
   else
     Init = llvm::UndefValue::get(LTy);
----------------
rjmccall wrote:
> tra wrote:
> > This is too hard to read. Inverting it makes it somewhat easier to understand -- `either opencl_local or device-side CUDA shared are undef`.
> > ```
> >   if (Ty.getAddressSpace() == LangAS::opencl_local 
> >       || (getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
> >           D.hasAttr<CUDASharedAttr>()))
> >     Init = llvm::UndefValue::get(LTy);
> >   else
> >     Init = EmitNullConstant(Ty);
> > ```
> > 
> I assume getLangOpts().CUDAIsDevice implies getLangOpts().CUDA, so you really only need to check CUDAIsDevice.  But it might be faster still to just check for the attribute.
Right. I think only attribute needs to be checked.


https://reviews.llvm.org/D44985





More information about the cfe-commits mailing list