[clang] [Clang][CIR][Neon] Add lowering for `vabsh_f16` (PR #177576)
Andrzej WarzyĆski via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 23 08:33:32 PST 2026
https://github.com/banach-space updated https://github.com/llvm/llvm-project/pull/177576
>From 92e60e603e30594a5ffcfcd07374b85c11a2a659 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Fri, 23 Jan 2026 11:58:09 +0000
Subject: [PATCH] [Clang][CIR][Neon] Add lowering for `vabsh_f16`
NOTE: This PR upstreams code from
* https://github.com/llvm/clangir.
This logic was originally implemented by Amr Hesham in
https://github.com/llvm/clangir/pull/1269. Further
modification were made by other ClangIR contributors.
Co-authored-by: Amr Hesham <amr96 at programmer.net>
---
.../lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp | 8 ++++-
.../CodeGenBuiltins/AArch64/neon/fullfp16.c | 31 +++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CIR/CodeGenBuiltins/AArch64/neon/fullfp16.c
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
index 93089eb585aa7..52cf20cb4fc14 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
@@ -1245,11 +1245,17 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned builtinID, const CallExpr *expr,
assert(!cir::MissingFeatures::neonSISDIntrinsics());
+ llvm::SmallVector<mlir::Value, 4> ops;
+ mlir::Location loc = getLoc(expr->getExprLoc());
+
// Handle non-overloaded intrinsics first.
switch (builtinID) {
default:
break;
- case NEON::BI__builtin_neon_vabsh_f16:
+ case NEON::BI__builtin_neon_vabsh_f16: {
+ ops.push_back(emitScalarExpr(expr->getArg(0)));
+ return cir::FAbsOp::create(builder, loc, ops);
+ }
case NEON::BI__builtin_neon_vaddq_p128:
case NEON::BI__builtin_neon_vldrq_p128:
case NEON::BI__builtin_neon_vstrq_p128:
diff --git a/clang/test/CIR/CodeGenBuiltins/AArch64/neon/fullfp16.c b/clang/test/CIR/CodeGenBuiltins/AArch64/neon/fullfp16.c
new file mode 100644
index 0000000000000..30d93d6a85b20
--- /dev/null
+++ b/clang/test/CIR/CodeGenBuiltins/AArch64/neon/fullfp16.c
@@ -0,0 +1,31 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64 -target-feature +fullfp16 -disable-O0-optnone -Werror -Wall -fclangir -emit-cir -o - %s | FileCheck %s --check-prefixes=ALL,CIR
+// RUN: %clang_cc1 -triple aarch64 -target-feature +fullfp16 -disable-O0-optnone -Werror -Wall -fclangir -emit-llvm -o - %s | opt -S -passes=mem2reg,simplifycfg | FileCheck %s --check-prefixes=ALL,LLVM
+// RUN: %clang_cc1 -triple aarch64 -target-feature +fullfp16 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,simplifycfg | FileCheck %s --check-prefixes=ALL,LLVM
+
+
+//=============================================================================
+// NOTES
+//
+// Tests for unconstrained intrinsics that require the fullfp16 extension.
+//
+// As these intrinsics expand to code with multiple compound and declaration
+// stmts, the LLVM output has been simplified with opt. `simplifycfg` was added
+// specifically for the CIR lowering path.
+//
+// TODO: Merge this file with clang/test/CodeGen/AArch64/v8.2a-fp16-intrinsics.c
+// (the source of these tests).
+//=============================================================================
+
+#include <arm_fp16.h>
+
+// ALL-LABEL: @test_vabsh_f16
+float16_t test_vabsh_f16(float16_t a) {
+// CIR: {{%.*}} = cir.fabs {{%.*}} : !cir.f16
+
+// LLVM-SAME: (half [[A:%.*]])
+// LLVM: [[ABS:%.*]] = call half @llvm.fabs.f16(half [[A]])
+// LLVM: ret half [[ABS]]
+ return vabsh_f16(a);
+}
More information about the cfe-commits
mailing list