[clang] [Clang][OpenCL] Mark scalar loads from constant address space invariant (PR #218356)

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 04:01:58 PDT 2026


================
@@ -2074,6 +2075,22 @@ llvm::Value *CodeGenFunction::emitScalarConstant(
   return Constant.getValue();
 }
 
+static bool isInvariantLoad(CodeGenFunction &CGF, LangAS TypeAS,
+                            llvm::Value *Ptr) {
+  if (TypeAS == LangAS::opencl_constant)
+    return true;
+
+  // CUDA represents constant memory as a declaration attribute, so the
+  // expression type uses the default address space. Recover the storage
+  // address space from the underlying global after the address-space cast.
+  if (!CGF.getLangOpts().CUDAIsDevice)
+    return false;
+  const auto *GV =
+      llvm::dyn_cast<llvm::GlobalValue>(llvm::getUnderlyingObject(Ptr));
----------------
arsenm wrote:

This should not be using getUnderlyingObject, this should only be using AST information 

https://github.com/llvm/llvm-project/pull/218356


More information about the cfe-commits mailing list