Skip to content

Commit ce442a0

Browse files
committed
[CIR][AMDGPU] Add lowering for amdgcn ds swizzle builtin
1 parent e0e0345 commit ce442a0

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ mlir::Value CIRGenFunction::emitAMDGPUBuiltinExpr(unsigned builtinId,
9191
case AMDGPU::BI__builtin_amdgcn_div_fmasf: {
9292
llvm_unreachable("div_fmas_* NYI");
9393
}
94-
case AMDGPU::BI__builtin_amdgcn_ds_swizzle:
94+
case AMDGPU::BI__builtin_amdgcn_ds_swizzle: {
95+
mlir::Value arg0 = emitScalarExpr(expr->getArg(0));
96+
mlir::Value arg1 = emitScalarExpr(expr->getArg(1));
97+
return LLVMIntrinsicCallOp::create(
98+
builder, getLoc(expr->getExprLoc()),
99+
builder.getStringAttr("amdgcn.ds.swizzle"), arg0.getType(),
100+
{arg0, arg1})
101+
.getResult();
102+
}
95103
case AMDGPU::BI__builtin_amdgcn_mov_dpp8:
96104
case AMDGPU::BI__builtin_amdgcn_mov_dpp:
97105
case AMDGPU::BI__builtin_amdgcn_update_dpp: {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,13 @@ __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: @_Z19test_ds_swizzle_i32Pii
223+
// CIR: cir.llvm.intrinsic "amdgcn.ds.swizzle" {{.*}} : (!s32i, !s32i) -> !s32i
224+
// LLVM: define{{.*}} void @_Z19test_ds_swizzle_i32Pii
225+
// LLVM: call i32 @llvm.amdgcn.ds.swizzle(i32 %{{.*}}, i32 32)
226+
// OGCG: define{{.*}} void @_Z19test_ds_swizzle_i32Pii
227+
// OGCG: call i32 @llvm.amdgcn.ds.swizzle(i32 %{{.*}}, i32 32)
228+
__device__ void test_ds_swizzle_i32(int* out, int a) {
229+
*out = __builtin_amdgcn_ds_swizzle(a, 32);
230+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,13 @@ 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+
// CIR-LABEL: @test_ds_swizzle
225+
// CIR: cir.llvm.intrinsic "amdgcn.ds.swizzle" {{.*}} : (!s32i, !s32i) -> !s32i
226+
// LLVM: define{{.*}} void @test_ds_swizzle
227+
// LLVM: call i32 @llvm.amdgcn.ds.swizzle(i32 %{{.*}}, i32 32)
228+
// OGCG: define{{.*}} void @test_ds_swizzle
229+
// OGCG: call i32 @llvm.amdgcn.ds.swizzle(i32 %{{.*}}, i32 32)
230+
void test_ds_swizzle(global int* out, int a) {
231+
*out = __builtin_amdgcn_ds_swizzle(a, 32);
232+
}

0 commit comments

Comments
 (0)