Skip to content

Commit

Permalink
[clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace (#94346)
Browse files Browse the repository at this point in the history
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 <kortbeek@synopsys.com>
  • Loading branch information
brunodf-snps and kortbeek-snps authored Jun 17, 2024
1 parent 6d973b4 commit c2d9f25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CodeGenCXX/init-invariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down

0 comments on commit c2d9f25

Please sign in to comment.