1 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip -fcuda-is-device -emit-llvm %s \
2 // RUN: -o - | FileCheck %s
4 // CHECK: define dso_local amdgpu_kernel void @_Z13shufflekernelv()
6 // CHECK-NEXT: [[TMP1:%.*]] = alloca i32, align 4, addrspace(5)
7 // CHECK-NEXT: [[TMP2:%.*]] = alloca i32, align 4, addrspace(5)
8 // CHECK-NEXT: [[TMP3:%.*]] = addrspacecast ptr addrspace(5) [[TMP1:%.*]] to ptr
9 // CHECK-NEXT: [[TMP4:%.*]] = addrspacecast ptr addrspace(5) [[TMP2:%.*]] to ptr
10 // CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[TMP3:%.*]], align 4
11 // CHECK-NEXT: [[TMP6:%.*]] = freeze i32 [[TMP5:%.*]]
12 // CHECK-NEXT: %call = call noundef i32 @_Z11__shfl_synciii(i32 noundef [[TMP6:%.*]], i32 noundef 64, i32 noundef 0) #4
13 // CHECK-NEXT: store i32 %call, ptr [[TMP4:%.*]], align 4
14 // CHECK-NEXT: ret void
16 // CHECK: define linkonce_odr noundef i32 @_Z11__shfl_synciii(i32 noundef [[TMP1:%.*]], i32 noundef [[TMP2:%.*]], i32 noundef [[TMP3:%.*]])
18 #define __global__ __attribute__((global))
19 #define __device__ __attribute__((device))
20 #define __maybe_undef __attribute__((maybe_undef))
23 static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE__;
25 __device__ static inline unsigned int __lane_id() {
26 return __builtin_amdgcn_mbcnt_hi(
27 -1, __builtin_amdgcn_mbcnt_lo(-1, 0));
32 int __shfl_sync(int __maybe_undef var, int src_lane, int width = warpSize) {
33 int self = __lane_id();
34 int index = src_lane + (self & ~(width-1));
35 return __builtin_amdgcn_ds_bpermute(index<<2, var);
43 res = __shfl_sync(t, WARP_SIZE, 0);