45 lines · plain
1// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip -fcuda-is-device -emit-llvm %s \2// RUN: -o - | FileCheck %s3 4// CHECK: define dso_local amdgpu_kernel void @_Z13shufflekernelv()5// CHECK-NEXT: entry: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 ptr9// CHECK-NEXT: [[TMP4:%.*]] = addrspacecast ptr addrspace(5) [[TMP2:%.*]] to ptr10// CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[TMP3:%.*]], align 411// 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) #413// CHECK-NEXT: store i32 %call, ptr [[TMP4:%.*]], align 414// CHECK-NEXT: ret void15 16// CHECK: define linkonce_odr noundef i32 @_Z11__shfl_synciii(i32 noundef [[TMP1:%.*]], i32 noundef [[TMP2:%.*]], i32 noundef [[TMP3:%.*]])17 18#define __global__ __attribute__((global))19#define __device__ __attribute__((device))20#define __maybe_undef __attribute__((maybe_undef))21#define WARP_SIZE 6422 23static constexpr int warpSize = WARP_SIZE;24 25__device__ static inline unsigned int __lane_id() {26 return __builtin_amdgcn_mbcnt_hi(27 -1, __builtin_amdgcn_mbcnt_lo(-1, 0));28}29 30__device__31inline32int __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);36}37 38__global__ void39shufflekernel()40{41 int t;42 int res;43 res = __shfl_sync(t, WARP_SIZE, 0);44}45