Skip to content

Commit b79b5ce

Browse files
doru1004ronlieb
authored andcommitted
Fix failure with team-wide allocated variable
Review: https://reviews.llvm.org/D147572 Change-Id: I1eaebd6440ff95632ebfc49f9a47a713e3970736
1 parent f706b41 commit b79b5ce

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3771,7 +3771,7 @@ Address CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
37713771
llvm::Type *VarTy = CGF.ConvertTypeForMem(VD->getType());
37723772
auto *GV = new llvm::GlobalVariable(
37733773
CGM.getModule(), VarTy, /*isConstant=*/false,
3774-
llvm::GlobalValue::InternalLinkage, llvm::Constant::getNullValue(VarTy),
3774+
llvm::GlobalValue::InternalLinkage, llvm::PoisonValue::get(VarTy),
37753775
VD->getName(),
37763776
/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
37773777
CGM.getContext().getTargetAddressSpace(AS));
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --prefix-filecheck-ir-name _ --global-value-regex "llvm.compiler.used" "_[0-9a-zA-Z]+A[0-9a-zA-Z]+pi[0-9a-zA-Z]+" "_[0-9a-zA-Z]+anotherPi" --version 2
2+
// REQUIRES: amdgpu-registered-target
3+
4+
5+
// Test target codegen - host bc file has to be created first.
6+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-amd.bc
7+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - | FileCheck %s --check-prefix=CHECK-AMD
8+
9+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvidia.bc
10+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-unknown-unknown -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvidia.bc -o - | FileCheck %s --check-prefix=CHECK-NVIDIA
11+
12+
// expected-no-diagnostics
13+
14+
#ifndef HEADER
15+
#define HEADER
16+
17+
typedef enum omp_allocator_handle_t {
18+
omp_null_allocator = 0,
19+
omp_default_mem_alloc = 1,
20+
omp_large_cap_mem_alloc = 2,
21+
omp_const_mem_alloc = 3,
22+
omp_high_bw_mem_alloc = 4,
23+
omp_low_lat_mem_alloc = 5,
24+
omp_cgroup_mem_alloc = 6,
25+
omp_pteam_mem_alloc = 7,
26+
omp_thread_mem_alloc = 8,
27+
KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
28+
} omp_allocator_handle_t;
29+
30+
//.
31+
// CHECK-AMD: @local_a = internal addrspace(3) global [10 x i32] poison, align 4
32+
//.
33+
// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] poison, align 4
34+
//.
35+
int main()
36+
{
37+
int N = 10000;
38+
int *a = new int[N];
39+
#pragma omp target data map(tofrom:a[:N])
40+
{
41+
#pragma omp target teams distribute parallel for
42+
for(int i = 0; i < N; i++)
43+
{
44+
int local_a[10];
45+
#pragma omp allocate(local_a) allocator(omp_pteam_mem_alloc)
46+
for(int j = 0; j < 10; j++)
47+
local_a[j] = a[(i + j) % N];
48+
a[i] = local_a[0];
49+
}
50+
}
51+
return a[17];
52+
}
53+
54+
#endif
55+
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
56+
// CHECK-AMD: {{.*}}
57+
// CHECK-NVIDIA: {{.*}}

0 commit comments

Comments
 (0)