[clang] [clang] Add arm64_neon.h wrapper (PR #196014)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 20:31:05 PDT 2026
https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/196014
>From 83e736eb7f036dea65c690defeb6f64a80b6e11d Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Wed, 6 May 2026 15:05:21 +0800
Subject: [PATCH 1/3] [clang] Add arm64_neon.h wrapper
Add an MSVC-compatible <arm64_neon.h> resource header that forwards to
Clang's generated <arm_neon.h>. This lets ARM64 Windows code using the
MSVC header name lower NEON intrinsics through Clang builtins instead of
leaving external neon_* calls such as neon_ld1m4_q32
Fix #195683
---
clang/lib/Headers/CMakeLists.txt | 1 +
clang/lib/Headers/arm64_neon.h | 15 +++++++++++++++
clang/lib/Headers/module.modulemap | 6 ++++++
clang/test/CodeGen/arm64-neon-header.c | 13 +++++++++++++
4 files changed, 35 insertions(+)
create mode 100644 clang/lib/Headers/arm64_neon.h
create mode 100644 clang/test/CodeGen/arm64-neon-header.c
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index d60ae2b5961e0..ce34f8b9410a7 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -55,6 +55,7 @@ set(arm_only_files
)
set(aarch64_only_files
+ arm64_neon.h
arm64intr.h
arm_neon_sve_bridge.h
)
diff --git a/clang/lib/Headers/arm64_neon.h b/clang/lib/Headers/arm64_neon.h
new file mode 100644
index 0000000000000..380e88d545621
--- /dev/null
+++ b/clang/lib/Headers/arm64_neon.h
@@ -0,0 +1,15 @@
+/*===---- arm64_neon.h - ARM64 NEON intrinsics -----------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ARM64_NEON_H
+#define __ARM64_NEON_H
+
+#include <arm_neon.h>
+
+#endif /* __ARM64_NEON_H */
diff --git a/clang/lib/Headers/module.modulemap b/clang/lib/Headers/module.modulemap
index 3fcaa55f1110e..c8f96df1672c1 100644
--- a/clang/lib/Headers/module.modulemap
+++ b/clang/lib/Headers/module.modulemap
@@ -50,6 +50,12 @@ module _Builtin_intrinsics [system] [extern_c] {
header "arm64intr.h"
export *
+
+ explicit module neon {
+ requires neon
+ header "arm64_neon.h"
+ export *
+ }
}
explicit module intel {
diff --git a/clang/test/CodeGen/arm64-neon-header.c b/clang/test/CodeGen/arm64-neon-header.c
new file mode 100644
index 0000000000000..f0aea4093caad
--- /dev/null
+++ b/clang/test/CodeGen/arm64-neon-header.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple arm64-pc-windows-msvc -fms-compatibility \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
+#include <arm64_neon.h>
+
+// CHECK-LABEL: define{{.*}} @test_vld1q_s32_x4(
+// CHECK-NOT: neon_ld1m4_q32
+// CHECK: call { <4 x i32>, <4 x i32>, <4 x i32>, <4 x i32> } @llvm.aarch64.neon.ld1x4.v4i32.p0(ptr {{.*}})
+// CHECK-NOT: neon_ld1m4_q32
+// CHECK: ret
+int32x4x4_t test_vld1q_s32_x4(int32_t const *a) {
+ return vld1q_s32_x4(a);
+}
>From 488841cfac761f25148fa5cf302b7266fb988bbc Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Wed, 6 May 2026 15:22:41 +0800
Subject: [PATCH 2/3] Add neon
---
clang/test/CodeGen/arm64-neon-header.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/CodeGen/arm64-neon-header.c b/clang/test/CodeGen/arm64-neon-header.c
index f0aea4093caad..e01a30bf36cee 100644
--- a/clang/test/CodeGen/arm64-neon-header.c
+++ b/clang/test/CodeGen/arm64-neon-header.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple arm64-pc-windows-msvc -fms-compatibility \
-// RUN: -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-pc-windows-msvc -target-feature +neon \
+// RUN: -fms-compatibility -emit-llvm -o - %s | FileCheck %s
#include <arm64_neon.h>
>From ae0a8aa1783d127a868b743f80336620da8b7181 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Thu, 7 May 2026 11:30:30 +0800
Subject: [PATCH 3/3] Add MSC_VER
---
clang/lib/Headers/arm64_neon.h | 6 ++++++
clang/test/CodeGen/arm64-neon-header.c | 3 ++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Headers/arm64_neon.h b/clang/lib/Headers/arm64_neon.h
index 380e88d545621..29803a8e455ae 100644
--- a/clang/lib/Headers/arm64_neon.h
+++ b/clang/lib/Headers/arm64_neon.h
@@ -7,9 +7,15 @@
*===-----------------------------------------------------------------------===
*/
+/* Only include this if we're compiling for the windows platform. */
+#ifndef _MSC_VER
+#include_next <arm64_neon.h>
+#else
+
#ifndef __ARM64_NEON_H
#define __ARM64_NEON_H
#include <arm_neon.h>
#endif /* __ARM64_NEON_H */
+#endif /* _MSC_VER */
diff --git a/clang/test/CodeGen/arm64-neon-header.c b/clang/test/CodeGen/arm64-neon-header.c
index e01a30bf36cee..3560bfeaad814 100644
--- a/clang/test/CodeGen/arm64-neon-header.c
+++ b/clang/test/CodeGen/arm64-neon-header.c
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -triple arm64-pc-windows-msvc -target-feature +neon \
-// RUN: -fms-compatibility -emit-llvm -o - %s | FileCheck %s
+// RUN: -fms-compatibility -fms-compatibility-version=19.00 \
+// RUN: -emit-llvm -o - %s | FileCheck %s
#include <arm64_neon.h>
More information about the cfe-commits
mailing list