[PATCH] D44985: [CUDA] Let device-side shared variables be initialized with undef
John McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 29 14:46:34 PDT 2018
rjmccall 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);
----------------
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.
https://reviews.llvm.org/D44985
More information about the cfe-commits
mailing list