1 // REQUIRES: amdgpu-registered-target
2 
3 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
4 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
5 // expected-no-diagnostics
6 #ifndef HEADER
7 #define HEADER
8 
9 #define N 1000
10 
test_amdgcn_target_tid_threads()11 int test_amdgcn_target_tid_threads() {
12 // CHECK-LABEL: define weak amdgpu_kernel void @{{.*}}test_amdgcn_target_tid_threads
13 
14   int arr[N];
15 
16 // CHECK: [[NUM_THREADS:%.+]] = call i32 @__kmpc_amdgcn_gpu_num_threads()
17 // CHECK: sub nuw i32 [[NUM_THREADS]], 64
18 // CHECK: call i32 @llvm.amdgcn.workitem.id.x()
19 #pragma omp target
20   for (int i = 0; i < N; i++) {
21     arr[i] = 1;
22   }
23 
24   return arr[0];
25 }
26 
test_amdgcn_target_tid_threads_simd()27 int test_amdgcn_target_tid_threads_simd() {
28 // CHECK-LABEL: define weak amdgpu_kernel void @{{.*}}test_amdgcn_target_tid_threads_simd
29 
30   int arr[N];
31 
32 // CHECK: [[NUM_THREADS:%.+]] = call i32 @__kmpc_amdgcn_gpu_num_threads()
33 // CHECK: call void @__kmpc_spmd_kernel_init(i32 [[NUM_THREADS]], i16 0)
34 #pragma omp target simd
35   for (int i = 0; i < N; i++) {
36     arr[i] = 1;
37   }
38   return arr[0];
39 }
40 
41 #endif
42