Skip to content

Commit f7a3356

Browse files
committed
[OMPIRBuilder] Use AS 0 for internal variables for AMDGPU
Signed-off-by: Nick Sarnie <[email protected]>
1 parent 0364baf commit f7a3356

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/test/OpenMP/force-usm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main(void) {
4646
// CHECK-USM-NEXT: br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
4747
// CHECK-USM: user_code.entry:
4848
// CHECK-USM-NEXT: store i32 1, ptr [[TMP0]], align 4
49-
// CHECK-USM-NEXT: [[TMP2:%.*]] = load ptr, ptr addrspace(1) @pGI_decl_tgt_ref_ptr, align 8
49+
// CHECK-USM-NEXT: [[TMP2:%.*]] = load ptr, ptr @pGI_decl_tgt_ref_ptr, align 8
5050
// CHECK-USM-NEXT: [[TMP3:%.*]] = load ptr, ptr [[TMP2]], align 8
5151
// CHECK-USM-NEXT: store i32 2, ptr [[TMP3]], align 4
5252
// CHECK-USM-NEXT: call void @__kmpc_target_deinit()

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8472,8 +8472,15 @@ GlobalVariable *OpenMPIRBuilder::getOrCreateInternalVariable(
84728472
// create different versions of the function for different OMP internal
84738473
// variables.
84748474
const DataLayout &DL = M.getDataLayout();
8475-
unsigned AddressSpaceVal =
8476-
AddressSpace ? *AddressSpace : DL.getDefaultGlobalsAddressSpace();
8475+
// TODO: Investigate why AMDGPU expects AS 0 for globals even though the
8476+
// default global AS is 1.
8477+
// See double-target-call-with-declare-target.f90 and
8478+
// declare-target-vars-in-target-region.f90 libomptarget
8479+
// tests.
8480+
unsigned AddressSpaceVal = AddressSpace ? *AddressSpace
8481+
: M.getTargetTriple().isAMDGPU()
8482+
? 0
8483+
: DL.getDefaultGlobalsAddressSpace();
84778484
auto Linkage = this->M.getTargetTriple().getArch() == Triple::wasm32
84788485
? GlobalValue::InternalLinkage
84798486
: GlobalValue::CommonLinkage;

0 commit comments

Comments
 (0)