[clang] [CIR][NEON] Add lowering for `vfmah_f16` (PR #181148)
Andrzej WarzyĆski via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 12 06:19:26 PST 2026
https://github.com/banach-space created https://github.com/llvm/llvm-project/pull/181148
As with other NEON builtins, reuse the existing default-lowering
tests to validate the CIR lowering path.
>From 7eaaf905be04a69a4e5ea880cf5a0208f4881ef7 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Thu, 12 Feb 2026 14:16:03 +0000
Subject: [PATCH] [CIR][NEON] Add lowering for `vfmah_f16`
As with other NEON builtins, reuse the existing default-lowering
tests to validate the CIR lowering path.
---
.../lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp | 21 +++++++++++++++++++
clang/test/CodeGen/AArch64/neon/fullfp16.c | 10 +++++++++
.../CodeGen/AArch64/v8.2a-fp16-intrinsics.c | 7 -------
3 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
index 71cf896aede10..0d4ed51920093 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
@@ -123,6 +123,17 @@ emitAArch64CompareBuiltinExpr(CIRGenFunction &cgf, CIRGenBuilderTy &builder,
return builder.createCast(loc, cir::CastKind::integral, cmp, retTy);
}
+// Emit an intrinsic where all operands are of the same type as the result.
+// Depending on mode, this may be a constrained floating-point intrinsic.
+static mlir::Value
+emitCallMaybeConstrainedBuiltin(CIRGenBuilderTy &builder, mlir::Location loc,
+ StringRef intrName, mlir::Type retTy,
+ llvm::SmallVector<mlir::Value> &ops) {
+ assert(!cir::MissingFeatures::emitConstrainedFPCall());
+
+ return builder.emitIntrinsicCallOp(loc, intrName, retTy, ops);
+}
+
bool CIRGenFunction::getAArch64SVEProcessedOperands(
unsigned builtinID, const CallExpr *expr, SmallVectorImpl<mlir::Value> &ops,
SVETypeFlags typeFlags) {
@@ -1508,7 +1519,17 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned builtinID, const CallExpr *expr,
case NEON::BI__builtin_neon_vsubh_f16:
case NEON::BI__builtin_neon_vmulh_f16:
case NEON::BI__builtin_neon_vdivh_f16:
+ cgm.errorNYI(expr->getSourceRange(),
+ std::string("unimplemented AArch64 builtin call: ") +
+ getContext().BuiltinInfo.getName(builtinID));
+ return mlir::Value{};
case NEON::BI__builtin_neon_vfmah_f16:
+ ops.push_back(emitScalarExpr(expr->getArg(1)));
+ ops.push_back(emitScalarExpr(expr->getArg(2)));
+ ops.push_back(emitScalarExpr(expr->getArg(0)));
+ return emitCallMaybeConstrainedBuiltin(builder, loc, "fma",
+ convertType(expr->getType()), ops);
+ break;
case NEON::BI__builtin_neon_vfmsh_f16:
case NEON::BI__builtin_neon_vaddd_s64:
case NEON::BI__builtin_neon_vaddd_u64:
diff --git a/clang/test/CodeGen/AArch64/neon/fullfp16.c b/clang/test/CodeGen/AArch64/neon/fullfp16.c
index f3268df2f4165..3a96107a3a0f6 100644
--- a/clang/test/CodeGen/AArch64/neon/fullfp16.c
+++ b/clang/test/CodeGen/AArch64/neon/fullfp16.c
@@ -50,3 +50,13 @@ float16_t test_vnegh_f16(float16_t a) {
// LLVM: ret half [[NEG]]
return vnegh_f16(a);
}
+
+// ALL-LABEL: test_vfmah_f16
+float16_t test_vfmah_f16(float16_t a, float16_t b, float16_t c) {
+// CIR: cir.call_llvm_intrinsic "fma" {{.*}} : (!cir.f16, !cir.f16, !cir.f16) -> !cir.f16
+
+// LLVM-SAME: half{{.*}} [[A:%.*]], half{{.*}} [[B:%.*]], half{{.*}} [[C:%.*]])
+// LLVM: [[FMA:%.*]] = call half @llvm.fma.f16(half [[B]], half [[C]], half [[A]])
+// LLVM: ret half [[FMA]]
+ return vfmah_f16(a, b, c);
+}
diff --git a/clang/test/CodeGen/AArch64/v8.2a-fp16-intrinsics.c b/clang/test/CodeGen/AArch64/v8.2a-fp16-intrinsics.c
index 353f02195721f..d6bfb1c607f81 100644
--- a/clang/test/CodeGen/AArch64/v8.2a-fp16-intrinsics.c
+++ b/clang/test/CodeGen/AArch64/v8.2a-fp16-intrinsics.c
@@ -620,13 +620,6 @@ float16_t test_vsubh_f16(float16_t a, float16_t b) {
return vsubh_f16(a, b);
}
-// CHECK-LABEL: test_vfmah_f16
-// CHECK: [[FMA:%.*]] = call half @llvm.fma.f16(half %b, half %c, half %a)
-// CHECK: ret half [[FMA]]
-float16_t test_vfmah_f16(float16_t a, float16_t b, float16_t c) {
- return vfmah_f16(a, b, c);
-}
-
// CHECK-LABEL: test_vfmsh_f16
// CHECK: [[SUB:%.*]] = fneg half %b
// CHECK: [[ADD:%.*]] = call half @llvm.fma.f16(half [[SUB]], half %c, half %a)
More information about the cfe-commits
mailing list