Skip to content

Commit 4916f0e

Browse files
authored
[CIR][AMDGPU] Add lowering for amdgcn readlane readfirstlane builtins (#2053)
This PR adds support for lowering of "_builtin_amdgcn_readlane" and "_builtin_amdgcn_readfirstlane" amdgpu builtins to clangIR. Followed similar lowering from reference clang->llvmir in clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp.
1 parent a90b91b commit 4916f0e

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ mlir::Value CIRGenFunction::emitAMDGPUBuiltinExpr(unsigned builtinId,
148148
return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.permlane64")
149149
.getScalarVal();
150150
}
151-
case AMDGPU::BI__builtin_amdgcn_readlane:
151+
case AMDGPU::BI__builtin_amdgcn_readlane: {
152+
return emitBuiltinWithOneOverloadedType<2>(expr, "amdgcn.readlane")
153+
.getScalarVal();
154+
}
152155
case AMDGPU::BI__builtin_amdgcn_readfirstlane: {
153-
llvm_unreachable("readlane_* NYI");
156+
return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.readfirstlane")
157+
.getScalarVal();
154158
}
155159
case AMDGPU::BI__builtin_amdgcn_div_fixup:
156160
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
@@ -285,3 +285,23 @@ __device__ void test_div_fmas_f64(double* out, double a, double b, double c, int
285285
__device__ void test_ds_swizzle_i32(int* out, int a) {
286286
*out = __builtin_amdgcn_ds_swizzle(a, 32);
287287
}
288+
289+
// CIR-LABEL: @_Z13test_readlanePiii
290+
// CIR: cir.llvm.intrinsic "amdgcn.readlane" {{.*}} : (!s32i, !s32i) -> !s32i
291+
// LLVM: define{{.*}} void @_Z13test_readlanePiii
292+
// LLVM: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
293+
// OGCG: define{{.*}} void @_Z13test_readlanePiii
294+
// OGCG: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
295+
__device__ void test_readlane(int* out, int a, int b) {
296+
*out = __builtin_amdgcn_readlane(a, b);
297+
}
298+
299+
// CIR-LABEL: @_Z18test_readfirstlanePii
300+
// CIR: cir.llvm.intrinsic "amdgcn.readfirstlane" {{.*}} : (!s32i) -> !s32i
301+
// LLVM: define{{.*}} void @_Z18test_readfirstlanePii
302+
// LLVM: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
303+
// OGCG: define{{.*}} void @_Z18test_readfirstlanePii
304+
// OGCG: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
305+
__device__ void test_readfirstlane(int* out, int a) {
306+
*out = __builtin_amdgcn_readfirstlane(a);
307+
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,23 @@ void test_div_fmas_f64(global double* out, double a, double b, double c, int d)
298298
void test_ds_swizzle(global int* out, int a) {
299299
*out = __builtin_amdgcn_ds_swizzle(a, 32);
300300
}
301+
302+
// CIR-LABEL: @test_readlane
303+
// CIR: cir.llvm.intrinsic "amdgcn.readlane" {{.*}} : (!s32i, !s32i) -> !s32i
304+
// LLVM: define{{.*}} void @test_readlane
305+
// LLVM: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
306+
// OGCG: define{{.*}} void @test_readlane
307+
// OGCG: call i32 @llvm.amdgcn.readlane.i32(i32 %{{.*}}, i32 %{{.*}})
308+
void test_readlane(global int* out, int a, int b) {
309+
*out = __builtin_amdgcn_readlane(a, b);
310+
}
311+
312+
// CIR-LABEL: @test_readfirstlane
313+
// CIR: cir.llvm.intrinsic "amdgcn.readfirstlane" {{.*}} : (!s32i) -> !s32i
314+
// LLVM: define{{.*}} void @test_readfirstlane
315+
// LLVM: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
316+
// OGCG: define{{.*}} void @test_readfirstlane
317+
// OGCG: call i32 @llvm.amdgcn.readfirstlane.i32(i32 %{{.*}})
318+
void test_readfirstlane(global int* out, int a) {
319+
*out = __builtin_amdgcn_readfirstlane(a);
320+
}

0 commit comments

Comments
 (0)