Skip to content

[clang] Recover necessary AddrSpaceCast #119246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3302,6 +3302,7 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
CharUnits Align = CGM.getContext().getDeclAlign(VD);
Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
}
Val = Builder.CreateAddrSpaceCast(Val, Wrapper->getReturnType());

Builder.CreateRet(Val);
}
Expand Down
16 changes: 16 additions & 0 deletions clang/test/OpenMP/amdgpu_threadprivate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -target-cpu gfx906 -fopenmp -nogpulib -fopenmp-is-target-device -emit-llvm %s -o - | FileCheck %s

// Don't crash with assertions build.

// CHECK: @MyGlobVar = external thread_local addrspace(1) global i32, align 4
// CHECK: define weak_odr hidden noundef ptr @_ZTW9MyGlobVar() #0 comdat {
// CHECK-NEXT: %1 = call align 4 ptr addrspace(1) @llvm.threadlocal.address.p1(ptr addrspace(1) align 4 @MyGlobVar)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support this intrinsic?

Copy link
Member Author

@JOE1994 JOE1994 Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For AMDGPU codegen) Doesn't seem so to me.

The intrinsic was added in 9701053

// CHECK-NEXT: %2 = addrspacecast ptr addrspace(1) %1 to ptr
// CHECK-NEXT: ret ptr %2
// CHECK-NEXT: }
int MyGlobVar;
#pragma omp threadprivate(MyGlobVar)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not crash for sure, but I wonder is this a valid use of OpenMP? I don't know what I should expect from this semantics.

int main() {
MyGlobVar = 1;
}

Loading