https://github.com/awayzjj updated 
https://github.com/llvm/llvm-project/pull/242166

>From 43b3ff20ca4ace83bfb4e69d27ee5ab958c371ac 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 | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp
index 81e2509efeb4c7..0f28dec9055c82 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 180f632b5050bf..f78f015626de6d 100644
--- a/clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip
+++ b/clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip
@@ -409,6 +409,21 @@ __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: %[[SRC0:.*]] = cir.load{{.*}}
+// CIR: %[[SRC1:.*]] = cir.load{{.*}}
+// CIR: %[[SRC2:.*]] = cir.load{{.*}}
+// CIR: cir.fshr %[[SRC0]], %[[SRC1]], %[[SRC2]] : !u32i
+// LLVM: define{{.*}} void @_Z13test_alignbitPjjjj
+// LLVM: %[[SRC0:.*]] = load i32
+// LLVM: %[[SRC1:.*]] = load i32
+// LLVM: %[[SRC2:.*]] = load i32
+// LLVM: call{{.*}} i32 @llvm.fshr.i32(i32 %[[SRC0]], i32 %[[SRC1]], i32 
%[[SRC2]])
+__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

Reply via email to