https://github.com/brunodf-snps created https://github.com/llvm/llvm-project/pull/94346
The `llvm.invariant.start` intrinsic is already overloaded to work with memory objects in any address space. We simply instantiate the intrinsic with the appropriate pointer type. Fixes #94345. >From ea1a8a67e840a718324a7256e3917207c5661ab5 Mon Sep 17 00:00:00 2001 From: Bruno De Fraine <brun...@synopsys.com> Date: Tue, 4 Jun 2024 14:44:30 +0200 Subject: [PATCH] [clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace The `llvm.invariant.start` intrinsic is already overloaded to work with memory objects in any address space. We simply instantiate the intrinsic with the appropriate pointer type. Fixes #94345. Co-authored-by: Vito Kortbeek <kortb...@synopsys.com> --- clang/lib/CodeGen/CGDeclCXX.cpp | 3 ++- clang/test/CodeGenCXX/init-invariant.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp index b047279912f6b..a0429435dbe7e 100644 --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -162,7 +162,8 @@ void CodeGenFunction::EmitInvariantStart(llvm::Constant *Addr, CharUnits Size) { // Grab the llvm.invariant.start intrinsic. llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start; // Overloaded address space type. - llvm::Type *ObjectPtr[1] = {Int8PtrTy}; + assert(Addr->getType()->isPointerTy() && "Address must be a pointer"); + llvm::Type *ObjectPtr[1] = {Addr->getType()}; llvm::Function *InvariantStart = CGM.getIntrinsic(InvStartID, ObjectPtr); // Emit a call with the size in bytes of the object. diff --git a/clang/test/CodeGenCXX/init-invariant.cpp b/clang/test/CodeGenCXX/init-invariant.cpp index fdd5753402ccb..974064b70a3c0 100644 --- a/clang/test/CodeGenCXX/init-invariant.cpp +++ b/clang/test/CodeGenCXX/init-invariant.cpp @@ -46,6 +46,8 @@ extern const C c = C(); int f(); // CHECK: @d ={{.*}} global i32 0 extern const int d = f(); +// CHECK: @d2 ={{.*}} addrspace(10) global i32 0 +extern const int __attribute__((address_space(10))) d2 = f(); void e() { static const A a = A(); @@ -67,6 +69,10 @@ void e() { // CHECK: store {{.*}}, ptr @d // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @d) +// CHECK: call noundef i32 @_Z1fv( +// CHECK: store {{.*}}, ptr addrspace(10) @d2 +// CHECK: call {{.*}}@llvm.invariant.start.p10(i64 4, ptr addrspace(10) @d2) + // CHECK-LABEL: define{{.*}} void @_Z1ev( // CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @_ZZ1evE1a) // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr {{.*}}@_ZZ1evE1a) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits