Skip to content

Commit 2f62037

Browse files
authored
Add SME2 builtins for pfalse and ptrue (#71953)
Extend pfalse and ptrue builtins with svcount_t return types to be enabled for sve2p1 and sme2 See ARM-software/acle#217
1 parent 69c4930 commit 2f62037

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

clang/include/clang/Basic/arm_sve.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,8 +1925,6 @@ def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", MergeNone, "aarch64_sv
19251925

19261926
let TargetGuard = "sve2p1" in {
19271927
def SVFCLAMP : SInst<"svclamp[_{d}]", "dddd", "hfd", MergeNone, "aarch64_sve_fclamp", [], []>;
1928-
def SVPTRUE_COUNT : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, "aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
1929-
def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", [IsOverloadNone]>;
19301928

19311929
def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, "aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;
19321930
def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", MergeNone, "aarch64_sve_pext_x2", [], [ImmCheck<1, ImmCheck0_1>]>;
@@ -2045,6 +2043,12 @@ def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, "aarch64_sv
20452043
defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
20462044
}
20472045

2046+
let TargetGuard = "sve2p1|sme2" in {
2047+
//FIXME: Replace IsStreamingCompatible with IsStreamingOrHasSVE2p1 when available
2048+
def SVPTRUE_COUNT : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, "aarch64_sve_ptrue_{d}", [IsOverloadNone, IsStreamingCompatible], []>;
2049+
2050+
def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", [IsOverloadNone, IsStreamingCompatible]>;
2051+
}
20482052

20492053
let TargetGuard = "sve2p1,b16b16" in {
20502054
defm SVMUL_BF : SInstZPZZ<"svmul", "b", "aarch64_sve_fmul", "aarch64_sve_fmul_u">;

clang/lib/Sema/Sema.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,8 +2084,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
20842084
if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
20852085
llvm::StringMap<bool> CallerFeatureMap;
20862086
Context.getFunctionFeatureMap(CallerFeatureMap, FD);
2087-
if (!Builtin::evaluateRequiredTargetFeatures(
2088-
"sve", CallerFeatureMap))
2087+
if (!Builtin::evaluateRequiredTargetFeatures("sve", CallerFeatureMap) &&
2088+
!Builtin::evaluateRequiredTargetFeatures("sme", CallerFeatureMap))
20892089
Diag(D->getLocation(), diag::err_sve_vector_in_non_sve_target) << Ty;
20902090
}
20912091
};
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
22
// REQUIRES: aarch64-registered-target
33
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
4+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
45
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
5-
// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
6-
// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
6+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
77
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
8-
#include <arm_sve.h>
8+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
99

10-
#ifdef SVE_OVERLOADED_FORMS
11-
// A simple used,unused... macro, long enough to represent any SVE builtin.
12-
#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
13-
#else
14-
#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
15-
#endif
10+
#include <arm_sve.h>
1611

1712
// CHECK-LABEL: @test_svpfalse_c(
1813
// CHECK-NEXT: entry:
@@ -24,7 +19,7 @@
2419
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call target("aarch64.svcount") @llvm.aarch64.sve.convert.from.svbool.taarch64.svcountt(<vscale x 16 x i1> zeroinitializer)
2520
// CPP-CHECK-NEXT: ret target("aarch64.svcount") [[TMP0]]
2621
//
27-
svcount_t test_svpfalse_c()
22+
svcount_t test_svpfalse_c(void) __arm_streaming_compatible
2823
{
29-
return SVE_ACLE_FUNC(svpfalse_c,,,)();
24+
return svpfalse_c();
3025
}

clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_ptrue.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
22
// REQUIRES: aarch64-registered-target
33
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s
4+
// RUN: %clang_cc1 -DTEST_SME2 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s
45
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
6+
// RUN: %clang_cc1 -DTEST_SME2 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
57

68
#include <arm_sve.h>
79

10+
#ifndef TEST_SME2
11+
#define ATTR
12+
#else
13+
#define ATTR __arm_streaming
14+
#endif
15+
816
// CHECK-LABEL: @test_svptrue_c8(
917
// CHECK-NEXT: entry:
1018
// CHECK-NEXT: [[TMP0:%.*]] = tail call target("aarch64.svcount") @llvm.aarch64.sve.ptrue.c8()
@@ -15,7 +23,7 @@
1523
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call target("aarch64.svcount") @llvm.aarch64.sve.ptrue.c8()
1624
// CPP-CHECK-NEXT: ret target("aarch64.svcount") [[TMP0]]
1725
//
18-
svcount_t test_svptrue_c8(void) {
26+
svcount_t test_svptrue_c8(void) ATTR {
1927
return svptrue_c8();
2028
}
2129

@@ -29,7 +37,7 @@ svcount_t test_svptrue_c8(void) {
2937
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call target("aarch64.svcount") @llvm.aarch64.sve.ptrue.c16()
3038
// CPP-CHECK-NEXT: ret target("aarch64.svcount") [[TMP0]]
3139
//
32-
svcount_t test_svptrue_c16(void) {
40+
svcount_t test_svptrue_c16(void) ATTR {
3341
return svptrue_c16();
3442
}
3543

@@ -43,7 +51,7 @@ svcount_t test_svptrue_c16(void) {
4351
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call target("aarch64.svcount") @llvm.aarch64.sve.ptrue.c32()
4452
// CPP-CHECK-NEXT: ret target("aarch64.svcount") [[TMP0]]
4553
//
46-
svcount_t test_svptrue_c32(void) {
54+
svcount_t test_svptrue_c32(void) ATTR {
4755
return svptrue_c32();
4856
}
4957

@@ -57,6 +65,6 @@ svcount_t test_svptrue_c32(void) {
5765
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call target("aarch64.svcount") @llvm.aarch64.sve.ptrue.c64()
5866
// CPP-CHECK-NEXT: ret target("aarch64.svcount") [[TMP0]]
5967
//
60-
svcount_t test_svptrue_c64(void) {
68+
svcount_t test_svptrue_c64(void) ATTR {
6169
return svptrue_c64();
6270
}

0 commit comments

Comments
 (0)