https://github.com/awayzjj created https://github.com/llvm/llvm-project/pull/242166
Lower the builtin to cir.fshr (and then llvm.fshr), matching classic CodeGen. Fixes part of #241525. >From 1e91472dd408c474a6abeb188b6eea013c23b631 Mon Sep 17 00:00:00 2001 From: awayzjj <[email protected]> Date: Fri, 13 Nov 2026 03:44:53 +0000 Subject: [PATCH] [CIR][AMDGPU] Add support for __builtin_amdgcn_alignbit Lower the builtin to cir.fshr (and then llvm.fshr), matching classic CodeGen. Fixes part of #241525. --- clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp | 10 ++++++---- clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp index 81e2509efeb4c..0f28dec9055c8 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp @@ -1303,10 +1303,12 @@ CIRGenFunction::emitAMDGPUBuiltinExpr(unsigned builtinId, return mlir::Value{}; } case AMDGPU::BI__builtin_amdgcn_alignbit: { - cgm.errorNYI(expr->getSourceRange(), - std::string("unimplemented AMDGPU builtin call: ") + - getContext().BuiltinInfo.getName(builtinId)); - return mlir::Value{}; + mlir::Value arg0 = emitScalarExpr(expr->getArg(0)); + mlir::Value arg1 = emitScalarExpr(expr->getArg(1)); + mlir::Value arg2 = emitScalarExpr(expr->getArg(2)); + mlir::Location loc = getLoc(expr->getExprLoc()); + mlir::Type ty = convertType(expr->getType()); + return cir::FshrOp::create(builder, loc, ty, arg0, arg1, arg2).getResult(); } case AMDGPU::BI__builtin_amdgcn_fence: { // The scope uses AMDGPU spelling on every target, like mapScopeToSPIRV. diff --git a/clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip b/clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip index 180f632b5050b..6b2384c7cf1d8 100644 --- a/clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip +++ b/clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip @@ -409,6 +409,15 @@ __device__ void test_lerp(unsigned int* out, unsigned int src0, unsigned int src *out = __builtin_amdgcn_lerp(src0, src1, src2); } +// CIR-LABEL: @_Z13test_alignbitPjjjj +// CIR: cir.fshr {{.*}} : !u32i +// LLVM: define{{.*}} void @_Z13test_alignbitPjjjj +// LLVM: call{{.*}} i32 @llvm.fshr.i32(i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}}) +__device__ void test_alignbit(unsigned int* out, unsigned int src0, unsigned int src1, + unsigned int src2) { + *out = __builtin_amdgcn_alignbit(src0, src1, src2); +} + // CIR-LABEL: @_Z9test_ubfePjjjj // CIR: cir.call_llvm_intrinsic "amdgcn.ubfe" {{.*}} : (!u32i, !u32i, !u32i) -> !u32i // LLVM: define{{.*}} void @_Z9test_ubfePjjjj _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
