Skip to content

Commit dcf11c5

Browse files
committed
[ARM][AArch64] Complex addition Neon intrinsics for Armv8.3-A
Summary: Add support for vcadd_* family of intrinsics. This set of intrinsics is available in Armv8.3-A. The fp16 versions require the FP16 extension, which has been available (opt-in) since Armv8.2-A. Reviewers: t.p.northover Reviewed By: t.p.northover Subscribers: t.p.northover, kristof.beyls, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D70862
1 parent af0babc commit dcf11c5

File tree

13 files changed

+328
-1
lines changed

13 files changed

+328
-1
lines changed

clang/include/clang/Basic/arm_neon.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,3 +1673,21 @@ let ArchGuard = "defined(__ARM_FEATURE_FP16FML) && defined(__aarch64__)" in {
16731673
def VFMLAL_LANEQ_HIGH : SOpInst<"vfmlal_laneq_high", "(F>)(F>)F(FQ)I", "hQh", OP_FMLAL_LN_Hi>;
16741674
def VFMLSL_LANEQ_HIGH : SOpInst<"vfmlsl_laneq_high", "(F>)(F>)F(FQ)I", "hQh", OP_FMLSL_LN_Hi>;
16751675
}
1676+
1677+
// v8.3-A Vector complex addition intrinsics
1678+
let ArchGuard = "defined(__ARM_FEATURE_COMPLEX) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)" in {
1679+
def VCADD_ROT90_FP16 : SInst<"vcadd_rot90", "...", "h">;
1680+
def VCADD_ROT270_FP16 : SInst<"vcadd_rot270", "...", "h">;
1681+
def VCADDQ_ROT90_FP16 : SInst<"vcaddq_rot90", "QQQ", "h">;
1682+
def VCADDQ_ROT270_FP16 : SInst<"vcaddq_rot270", "QQQ", "h">;
1683+
}
1684+
let ArchGuard = "defined(__ARM_FEATURE_COMPLEX)" in {
1685+
def VCADD_ROT90 : SInst<"vcadd_rot90", "...", "f">;
1686+
def VCADD_ROT270 : SInst<"vcadd_rot270", "...", "f">;
1687+
def VCADDQ_ROT90 : SInst<"vcaddq_rot90", "QQQ", "f">;
1688+
def VCADDQ_ROT270 : SInst<"vcaddq_rot270", "QQQ", "f">;
1689+
}
1690+
let ArchGuard = "defined(__ARM_FEATURE_COMPLEX) && defined(__aarch64__)" in {
1691+
def VCADDQ_ROT90_FP64 : SInst<"vcaddq_rot90", "QQQ", "d">;
1692+
def VCADDQ_ROT270_FP64 : SInst<"vcaddq_rot270", "QQQ", "d">;
1693+
}

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void AArch64TargetInfo::getTargetDefinesARMV82A(const LangOptions &Opts,
158158

159159
void AArch64TargetInfo::getTargetDefinesARMV83A(const LangOptions &Opts,
160160
MacroBuilder &Builder) const {
161+
Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
161162
Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
162163
// Also include the Armv8.2 defines
163164
getTargetDefinesARMV82A(Opts, Builder);

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,13 @@ void ARMTargetInfo::getTargetDefinesARMV82A(const LangOptions &Opts,
580580
getTargetDefinesARMV81A(Opts, Builder);
581581
}
582582

583+
void ARMTargetInfo::getTargetDefinesARMV83A(const LangOptions &Opts,
584+
MacroBuilder &Builder) const {
585+
// Also include the ARMv8.2-A defines
586+
Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
587+
getTargetDefinesARMV82A(Opts, Builder);
588+
}
589+
583590
void ARMTargetInfo::getTargetDefines(const LangOptions &Opts,
584591
MacroBuilder &Builder) const {
585592
// Target identification.
@@ -809,6 +816,11 @@ void ARMTargetInfo::getTargetDefines(const LangOptions &Opts,
809816
case llvm::ARM::ArchKind::ARMV8_2A:
810817
getTargetDefinesARMV82A(Opts, Builder);
811818
break;
819+
case llvm::ARM::ArchKind::ARMV8_3A:
820+
case llvm::ARM::ArchKind::ARMV8_4A:
821+
case llvm::ARM::ArchKind::ARMV8_5A:
822+
getTargetDefinesARMV83A(Opts, Builder);
823+
break;
812824
}
813825
}
814826

clang/lib/Basic/Targets/ARM.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo {
148148

149149
void getTargetDefinesARMV81A(const LangOptions &Opts,
150150
MacroBuilder &Builder) const;
151-
152151
void getTargetDefinesARMV82A(const LangOptions &Opts,
153152
MacroBuilder &Builder) const;
153+
void getTargetDefinesARMV83A(const LangOptions &Opts,
154+
MacroBuilder &Builder) const;
154155
void getTargetDefines(const LangOptions &Opts,
155156
MacroBuilder &Builder) const override;
156157

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4454,6 +4454,10 @@ static const NeonIntrinsicInfo ARMSIMDIntrinsicMap [] = {
44544454
NEONMAP1(vaesmcq_v, arm_neon_aesmc, 0),
44554455
NEONMAP1(vbsl_v, arm_neon_vbsl, AddRetType),
44564456
NEONMAP1(vbslq_v, arm_neon_vbsl, AddRetType),
4457+
NEONMAP1(vcadd_rot270_v, arm_neon_vcadd_rot270, Add1ArgType),
4458+
NEONMAP1(vcadd_rot90_v, arm_neon_vcadd_rot90, Add1ArgType),
4459+
NEONMAP1(vcaddq_rot270_v, arm_neon_vcadd_rot270, Add1ArgType),
4460+
NEONMAP1(vcaddq_rot90_v, arm_neon_vcadd_rot90, Add1ArgType),
44574461
NEONMAP1(vcage_v, arm_neon_vacge, 0),
44584462
NEONMAP1(vcageq_v, arm_neon_vacge, 0),
44594463
NEONMAP1(vcagt_v, arm_neon_vacgt, 0),
@@ -4727,6 +4731,10 @@ static const NeonIntrinsicInfo AArch64SIMDIntrinsicMap[] = {
47274731
NEONMAP1(vaeseq_v, aarch64_crypto_aese, 0),
47284732
NEONMAP1(vaesimcq_v, aarch64_crypto_aesimc, 0),
47294733
NEONMAP1(vaesmcq_v, aarch64_crypto_aesmc, 0),
4734+
NEONMAP1(vcadd_rot270_v, aarch64_neon_vcadd_rot270, Add1ArgType),
4735+
NEONMAP1(vcadd_rot90_v, aarch64_neon_vcadd_rot90, Add1ArgType),
4736+
NEONMAP1(vcaddq_rot270_v, aarch64_neon_vcadd_rot270, Add1ArgType),
4737+
NEONMAP1(vcaddq_rot90_v, aarch64_neon_vcadd_rot90, Add1ArgType),
47304738
NEONMAP1(vcage_v, aarch64_neon_facge, 0),
47314739
NEONMAP1(vcageq_v, aarch64_neon_facge, 0),
47324740
NEONMAP1(vcagt_v, aarch64_neon_facgt, 0),
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// RUN: %clang -target aarch64-arm-none-eabi -march=armv8.3-a+fp16 %s -S -emit-llvm -o - | FileCheck %s
2+
3+
#include <arm_neon.h>
4+
5+
void foo16x4_rot90(float16x4_t a, float16x4_t b)
6+
{
7+
// CHECK: call <4 x half> @llvm.aarch64.neon.vcadd.rot90.v4f16
8+
float16x4_t result = vcadd_rot90_f16(a, b);
9+
}
10+
11+
void foo32x2_rot90(float32x2_t a, float32x2_t b)
12+
{
13+
// CHECK: call <2 x float> @llvm.aarch64.neon.vcadd.rot90.v2f32
14+
float32x2_t result = vcadd_rot90_f32(a, b);
15+
}
16+
17+
void foo16x8_rot90(float16x8_t a, float16x8_t b)
18+
{
19+
// CHECK: call <8 x half> @llvm.aarch64.neon.vcadd.rot90.v8f16
20+
float16x8_t result = vcaddq_rot90_f16(a, b);
21+
}
22+
23+
void foo32x4_rot90(float32x4_t a, float32x4_t b)
24+
{
25+
// CHECK: call <4 x float> @llvm.aarch64.neon.vcadd.rot90.v4f32
26+
float32x4_t result = vcaddq_rot90_f32(a, b);
27+
}
28+
29+
void foo64x2_rot90(float64x2_t a, float64x2_t b)
30+
{
31+
// CHECK: call <2 x double> @llvm.aarch64.neon.vcadd.rot90.v2f64
32+
float64x2_t result = vcaddq_rot90_f64(a, b);
33+
}
34+
35+
void foo16x4_rot270(float16x4_t a, float16x4_t b)
36+
{
37+
// CHECK: call <4 x half> @llvm.aarch64.neon.vcadd.rot270.v4f16
38+
float16x4_t result = vcadd_rot270_f16(a, b);
39+
}
40+
41+
void foo32x2_rot270(float32x2_t a, float32x2_t b)
42+
{
43+
// CHECK: call <2 x float> @llvm.aarch64.neon.vcadd.rot270.v2f32
44+
float32x2_t result = vcadd_rot270_f32(a, b);
45+
}
46+
47+
void foo16x8_rot270(float16x8_t a, float16x8_t b)
48+
{
49+
// CHECK: call <8 x half> @llvm.aarch64.neon.vcadd.rot270.v8f16
50+
float16x8_t result = vcaddq_rot270_f16(a, b);
51+
}
52+
53+
void foo32x4_rot270(float32x4_t a, float32x4_t b)
54+
{
55+
// CHECK: call <4 x float> @llvm.aarch64.neon.vcadd.rot270.v4f32
56+
float32x4_t result = vcaddq_rot270_f32(a, b);
57+
}
58+
59+
void foo64x2_rot270(float64x2_t a, float64x2_t b)
60+
{
61+
// CHECK: call <2 x double> @llvm.aarch64.neon.vcadd.rot270.v2f64
62+
float64x2_t result = vcaddq_rot270_f64(a, b);
63+
}

clang/test/CodeGen/arm-neon-vcadd.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %clang -target arm-arm-none-eabi -march=armv8.3-a+fp16 %s -S -emit-llvm -o - | opt -S -sroa | FileCheck %s
2+
3+
#include <arm_neon.h>
4+
5+
void foo16x4_rot90(float16x4_t a, float16x4_t b)
6+
{
7+
// CHECK: call <4 x half> @llvm.arm.neon.vcadd.rot90.v4f16
8+
float16x4_t result = vcadd_rot90_f16(a, b);
9+
}
10+
11+
void foo32x2_rot90(float32x2_t a, float32x2_t b)
12+
{
13+
// CHECK: call <2 x float> @llvm.arm.neon.vcadd.rot90.v2f32
14+
float32x2_t result = vcadd_rot90_f32(a, b);
15+
}
16+
17+
void foo16x8_rot90(float16x8_t a, float16x8_t b)
18+
{
19+
// CHECK: call <8 x half> @llvm.arm.neon.vcadd.rot90.v8f16
20+
float16x8_t result = vcaddq_rot90_f16(a, b);
21+
}
22+
23+
void foo32x4_rot90(float32x4_t a, float32x4_t b)
24+
{
25+
// CHECK: call <4 x float> @llvm.arm.neon.vcadd.rot90.v4f32
26+
float32x4_t result = vcaddq_rot90_f32(a, b);
27+
}
28+
29+
void foo16x4_rot270(float16x4_t a, float16x4_t b)
30+
{
31+
// CHECK: call <4 x half> @llvm.arm.neon.vcadd.rot270.v4f16
32+
float16x4_t result = vcadd_rot270_f16(a, b);
33+
}
34+
35+
void foo32x2_rot270(float32x2_t a, float32x2_t b)
36+
{
37+
// CHECK: call <2 x float> @llvm.arm.neon.vcadd.rot270.v2f32
38+
float32x2_t result = vcadd_rot270_f32(a, b);
39+
}
40+
41+
void foo16x8_rot270(float16x8_t a, float16x8_t b)
42+
{
43+
// CHECK: call <8 x half> @llvm.arm.neon.vcadd.rot270.v8f16
44+
float16x8_t result = vcaddq_rot270_f16(a, b);
45+
}
46+
47+
void foo32x4_rot270(float32x4_t a, float32x4_t b)
48+
{
49+
// CHECK: call <4 x float> @llvm.arm.neon.vcadd.rot270.v4f32
50+
float32x4_t result = vcaddq_rot270_f32(a, b);
51+
}

llvm/include/llvm/IR/IntrinsicsAArch64.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ let TargetPrefix = "aarch64", IntrProperties = [IntrNoMem] in {
446446
def int_aarch64_neon_fmlsl : AdvSIMD_FP16FML_Intrinsic;
447447
def int_aarch64_neon_fmlal2 : AdvSIMD_FP16FML_Intrinsic;
448448
def int_aarch64_neon_fmlsl2 : AdvSIMD_FP16FML_Intrinsic;
449+
450+
// v8.3-A Floating-point complex add
451+
def int_aarch64_neon_vcadd_rot90 : AdvSIMD_2VectorArg_Intrinsic;
452+
def int_aarch64_neon_vcadd_rot270 : AdvSIMD_2VectorArg_Intrinsic;
449453
}
450454

451455
let TargetPrefix = "aarch64" in { // All intrinsics start with "llvm.aarch64.".

llvm/include/llvm/IR/IntrinsicsARM.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@ def int_arm_vctp16 : Intrinsic<[llvm_v8i1_ty], [llvm_i32_ty], [IntrNoMem]>;
778778
def int_arm_vctp32 : Intrinsic<[llvm_v4i1_ty], [llvm_i32_ty], [IntrNoMem]>;
779779
def int_arm_vctp64 : Intrinsic<[llvm_v2i1_ty], [llvm_i32_ty], [IntrNoMem]>;
780780

781+
// v8.3-A Floating-point complex add
782+
def int_arm_neon_vcadd_rot90 : Neon_2Arg_Intrinsic;
783+
def int_arm_neon_vcadd_rot270 : Neon_2Arg_Intrinsic;
784+
781785
// GNU eabi mcount
782786
def int_arm_gnu_eabi_mcount : Intrinsic<[],
783787
[],

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,29 @@ defm FCADD : SIMDThreeSameVectorComplexHSD<1, 0b111, complexrotateopodd,
757757
defm FCMLA : SIMDIndexedTiedComplexHSD<1, 0, 1, complexrotateop, "fcmla",
758758
null_frag>;
759759

760+
let Predicates = [HasComplxNum, HasNEON, HasFullFP16] in {
761+
def : Pat<(v4f16 (int_aarch64_neon_vcadd_rot90 (v4f16 V64:$Rn), (v4f16 V64:$Rm))),
762+
(FCADDv4f16 (v4f16 V64:$Rn), (v4f16 V64:$Rm), (i32 0))>;
763+
def : Pat<(v4f16 (int_aarch64_neon_vcadd_rot270 (v4f16 V64:$Rn), (v4f16 V64:$Rm))),
764+
(FCADDv4f16 (v4f16 V64:$Rn), (v4f16 V64:$Rm), (i32 1))>;
765+
def : Pat<(v8f16 (int_aarch64_neon_vcadd_rot90 (v8f16 V128:$Rn), (v8f16 V128:$Rm))),
766+
(FCADDv8f16 (v8f16 V128:$Rn), (v8f16 V128:$Rm), (i32 0))>;
767+
def : Pat<(v8f16 (int_aarch64_neon_vcadd_rot270 (v8f16 V128:$Rn), (v8f16 V128:$Rm))),
768+
(FCADDv8f16 (v8f16 V128:$Rn), (v8f16 V128:$Rm), (i32 1))>;
769+
}
770+
let Predicates = [HasComplxNum, HasNEON] in {
771+
def : Pat<(v2f32 (int_aarch64_neon_vcadd_rot90 (v2f32 V64:$Rn), (v2f32 V64:$Rm))),
772+
(FCADDv2f32 (v2f32 V64:$Rn), (v2f32 V64:$Rm), (i32 0))>;
773+
def : Pat<(v2f32 (int_aarch64_neon_vcadd_rot270 (v2f32 V64:$Rn), (v2f32 V64:$Rm))),
774+
(FCADDv2f32 (v2f32 V64:$Rn), (v2f32 V64:$Rm), (i32 1))>;
775+
foreach Ty = [v4f32, v2f64] in {
776+
def : Pat<(Ty (int_aarch64_neon_vcadd_rot90 (Ty V128:$Rn), (Ty V128:$Rm))),
777+
(!cast<Instruction>("FCADD"#Ty) (Ty V128:$Rn), (Ty V128:$Rm), (i32 0))>;
778+
def : Pat<(Ty (int_aarch64_neon_vcadd_rot270 (Ty V128:$Rn), (Ty V128:$Rm))),
779+
(!cast<Instruction>("FCADD"#Ty) (Ty V128:$Rn), (Ty V128:$Rm), (i32 1))>;
780+
}
781+
}
782+
760783
// v8.3a Pointer Authentication
761784
// These instructions inhabit part of the hint space and so can be used for
762785
// armv8 targets

0 commit comments

Comments
 (0)