Skip to content

Commit 6ee9e16

Browse files
committed
[CIR][AMDGPU] Add lowering for amdgcm readlane readfirstlane builtins
1 parent e0e0345 commit 6ee9e16

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ mlir::Value CIRGenFunction::emitAMDGPUBuiltinExpr(unsigned builtinId,
102102
case AMDGPU::BI__builtin_amdgcn_permlane64: {
103103
llvm_unreachable("permlane_* NYI");
104104
}
105-
case AMDGPU::BI__builtin_amdgcn_readlane:
105+
case AMDGPU::BI__builtin_amdgcn_readlane: {
106+
return emitBuiltinWithOneOverloadedType<2>(expr, "amdgcn.readlane")
107+
.getScalarVal();
108+
}
106109
case AMDGPU::BI__builtin_amdgcn_readfirstlane: {
107-
llvm_unreachable("readlane_* NYI");
110+
return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.readfirstlane")
111+
.getScalarVal();
108112
}
109113
case AMDGPU::BI__builtin_amdgcn_div_fixup:
110114
case AMDGPU::BI__builtin_amdgcn_div_fixupf:

clang/test/CIR/CodeGen/HIP/builtins-amdgcn.hip

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,23 @@ __device__ void test_wave_reduce_add_u32_iterative_i32(int* out, int in) {
218218
__device__ void test_wave_reduce_add_u32_dpp_i32(int* out, int in) {
219219
*out = __builtin_amdgcn_wave_reduce_add_u32(in, 2);
220220
}
221+
222+
// CIR-LABEL: @_Z13test_readlanePiii
223+
// CIR: cir.llvm.intrinsic "amdgcn.readlane" {{.*}} : (!s32i, !s32i) -> !s32i
224+
// LLVM: define{{.*}} void @_Z13test_readlanePiii
225+
// LLVM: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
226+
// OGCG: define{{.*}} void @_Z13test_readlanePiii
227+
// OGCG: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
228+
__device__ void test_readlane(int* out, int a, int b) {
229+
*out = __builtin_amdgcn_readlane(a, b);
230+
}
231+
232+
// CIR-LABEL: @_Z18test_readfirstlanePii
233+
// CIR: cir.llvm.intrinsic "amdgcn.readfirstlane" {{.*}} : (!s32i) -> !s32i
234+
// LLVM: define{{.*}} void @_Z18test_readfirstlanePii
235+
// LLVM: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
236+
// OGCG: define{{.*}} void @_Z18test_readfirstlanePii
237+
// OGCG: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
238+
__device__ void test_readfirstlane(int* out, int a) {
239+
*out = __builtin_amdgcn_readfirstlane(a);
240+
}

clang/test/CIR/CodeGen/OpenCL/builtins_amdgcn.cl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,24 @@ void test_wave_reduce_add_u32_iterative(global int* out, int in) {
220220
void test_wave_reduce_add_u32_dpp(global int* out, int in) {
221221
*out = __builtin_amdgcn_wave_reduce_add_u32(in, 2);
222222
}
223+
224+
225+
// CIR-LABEL: @test_readlane
226+
// CIR: cir.llvm.intrinsic "amdgcn.readlane" {{.*}} : (!s32i, !s32i) -> !s32i
227+
// LLVM: define{{.*}} void @test_readlane
228+
// LLVM: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
229+
// OGCG: define{{.*}} void @test_readlane
230+
// OGCG: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
231+
void test_readlane(global int* out, int a, int b) {
232+
*out = __builtin_amdgcn_readlane(a, b);
233+
}
234+
235+
// CIR-LABEL: @test_readfirstlane
236+
// CIR: cir.llvm.intrinsic "amdgcn.readfirstlane" {{.*}} : (!s32i) -> !s32i
237+
// LLVM: define{{.*}} void @test_readfirstlane
238+
// LLVM: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
239+
// OGCG: define{{.*}} void @test_readfirstlane
240+
// OGCG: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
241+
void test_readfirstlane(global int* out, int a) {
242+
*out = __builtin_amdgcn_readfirstlane(a);
243+
}

0 commit comments

Comments
 (0)