Skip to content

Commit e8b7d8b

Browse files
authored
[FMV][AArch64] Remove features which expose non exploitable runtime behavior. (#114387)
Features ebf16, memtag3, and rpres allow existing instructions to behave differently depending on the value of certain control registers. FMV does not read the content of control registers making these features unsuitable for runtime dispatch. See the ACLE patch for more info: ARM-software/acle#355
1 parent f8b9616 commit e8b7d8b

File tree

11 files changed

+29
-47
lines changed

11 files changed

+29
-47
lines changed

clang/test/CodeGen/aarch64-cpu-supports-target.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ int check_all_feature() {
99
return 3;
1010
else if (__builtin_cpu_supports("fcma+rcpc+rcpc2+rcpc3+frintts+dgh"))
1111
return 4;
12-
else if (__builtin_cpu_supports("i8mm+bf16+ebf16+rpres+sve"))
12+
else if (__builtin_cpu_supports("i8mm+bf16+sve"))
1313
return 5;
1414
else if (__builtin_cpu_supports("sve+ebf16+i8mm+f32mm+f64mm"))
1515
return 6;
1616
else if (__builtin_cpu_supports("sve2+sve2-aes+sve2-pmull128"))
1717
return 7;
1818
else if (__builtin_cpu_supports("sve2-bitperm+sve2-sha3+sve2-sm4"))
1919
return 8;
20-
else if (__builtin_cpu_supports("sme+memtag+memtag3+sb"))
20+
else if (__builtin_cpu_supports("sme+memtag+sb"))
2121
return 9;
2222
else if (__builtin_cpu_supports("predres+ssbs+ssbs2+bti+ls64+ls64_v"))
2323
return 10;

clang/test/CodeGen/aarch64-fmv-dependencies.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// CHECK: define dso_local i32 @fmv._Maes() #[[aes:[0-9]+]] {
77
__attribute__((target_version("aes"))) int fmv(void) { return 0; }
88

9-
// CHECK: define dso_local i32 @fmv._Mbf16() #[[bf16_ebf16:[0-9]+]] {
9+
// CHECK: define dso_local i32 @fmv._Mbf16() #[[bf16:[0-9]+]] {
1010
__attribute__((target_version("bf16"))) int fmv(void) { return 0; }
1111

1212
// CHECK: define dso_local i32 @fmv._Mbti() #[[bti:[0-9]+]] {
@@ -30,9 +30,6 @@ __attribute__((target_version("dpb"))) int fmv(void) { return 0; }
3030
// CHECK: define dso_local i32 @fmv._Mdpb2() #[[dpb2:[0-9]+]] {
3131
__attribute__((target_version("dpb2"))) int fmv(void) { return 0; }
3232

33-
// CHECK: define dso_local i32 @fmv._Mebf16() #[[bf16_ebf16:[0-9]+]] {
34-
__attribute__((target_version("ebf16"))) int fmv(void) { return 0; }
35-
3633
// CHECK: define dso_local i32 @fmv._Mf32mm() #[[f32mm:[0-9]+]] {
3734
__attribute__((target_version("f32mm"))) int fmv(void) { return 0; }
3835

@@ -75,9 +72,6 @@ __attribute__((target_version("lse"))) int fmv(void) { return 0; }
7572
// CHECK: define dso_local i32 @fmv._Mmemtag() #[[memtag:[0-9]+]] {
7673
__attribute__((target_version("memtag"))) int fmv(void) { return 0; }
7774

78-
// CHECK: define dso_local i32 @fmv._Mmemtag3() #[[memtag:[0-9]+]] {
79-
__attribute__((target_version("memtag3"))) int fmv(void) { return 0; }
80-
8175
// CHECK: define dso_local i32 @fmv._Mmops() #[[mops:[0-9]+]] {
8276
__attribute__((target_version("mops"))) int fmv(void) { return 0; }
8377

@@ -99,9 +93,6 @@ __attribute__((target_version("rdm"))) int fmv(void) { return 0; }
9993
// CHECK: define dso_local i32 @fmv._Mrng() #[[rng:[0-9]+]] {
10094
__attribute__((target_version("rng"))) int fmv(void) { return 0; }
10195

102-
// CHECK: define dso_local i32 @fmv._Mrpres() #[[ATTR0:[0-9]+]] {
103-
__attribute__((target_version("rpres"))) int fmv(void) { return 0; }
104-
10596
// CHECK: define dso_local i32 @fmv._Msb() #[[sb:[0-9]+]] {
10697
__attribute__((target_version("sb"))) int fmv(void) { return 0; }
10798

@@ -163,7 +154,7 @@ int caller() {
163154
}
164155

165156
// CHECK: attributes #[[aes]] = { {{.*}} "target-features"="+aes,+fp-armv8,+neon,+outline-atomics,+v8a"
166-
// CHECK: attributes #[[bf16_ebf16]] = { {{.*}} "target-features"="+bf16,+fp-armv8,+neon,+outline-atomics,+v8a"
157+
// CHECK: attributes #[[bf16]] = { {{.*}} "target-features"="+bf16,+fp-armv8,+neon,+outline-atomics,+v8a"
167158
// CHECK: attributes #[[bti]] = { {{.*}} "target-features"="+bti,+fp-armv8,+neon,+outline-atomics,+v8a"
168159
// CHECK: attributes #[[crc]] = { {{.*}} "target-features"="+crc,+fp-armv8,+neon,+outline-atomics,+v8a"
169160
// CHECK: attributes #[[ATTR0]] = { {{.*}} "target-features"="+fp-armv8,+neon,+outline-atomics,+v8a"

clang/test/CodeGen/attr-target-version.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ int foo() {
2727
inline int __attribute__((target_version("sha2+aes+f64mm"))) fmv_inline(void) { return 1; }
2828
inline int __attribute__((target_version("fp16+fcma+rdma+sme+ fp16 "))) fmv_inline(void) { return 2; }
2929
inline int __attribute__((target_version("sha3+i8mm+f32mm"))) fmv_inline(void) { return 12; }
30-
inline int __attribute__((target_version("dit+ebf16"))) fmv_inline(void) { return 8; }
30+
inline int __attribute__((target_version("dit+bf16"))) fmv_inline(void) { return 8; }
3131
inline int __attribute__((target_version("dpb+rcpc2 "))) fmv_inline(void) { return 6; }
3232
inline int __attribute__((target_version(" dpb2 + jscvt"))) fmv_inline(void) { return 7; }
3333
inline int __attribute__((target_version("rcpc+frintts"))) fmv_inline(void) { return 3; }
3434
inline int __attribute__((target_version("sve+bf16"))) fmv_inline(void) { return 4; }
3535
inline int __attribute__((target_version("sve2-aes+sve2-sha3"))) fmv_inline(void) { return 5; }
3636
inline int __attribute__((target_version("sve2+sve2-aes+sve2-bitperm"))) fmv_inline(void) { return 9; }
3737
inline int __attribute__((target_version("sve2-sm4+memtag"))) fmv_inline(void) { return 10; }
38-
inline int __attribute__((target_version("memtag3+rcpc3+mops"))) fmv_inline(void) { return 11; }
38+
inline int __attribute__((target_version("memtag+rcpc3+mops"))) fmv_inline(void) { return 11; }
3939
inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { return 13; }
4040
inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { return 14; }
4141
inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 15; }
@@ -680,7 +680,7 @@ int caller(void) { return used_def_without_default_decl() + used_decl_without_de
680680
//
681681
//
682682
// CHECK: Function Attrs: noinline nounwind optnone
683-
// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MditMebf16
683+
// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mbf16Mdit
684684
// CHECK-SAME: () #[[ATTR28:[0-9]+]] {
685685
// CHECK-NEXT: entry:
686686
// CHECK-NEXT: ret i32 8
@@ -736,7 +736,7 @@ int caller(void) { return used_def_without_default_decl() + used_decl_without_de
736736
//
737737
//
738738
// CHECK: Function Attrs: noinline nounwind optnone
739-
// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mmemtag3MmopsMrcpc3
739+
// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MmemtagMmopsMrcpc3
740740
// CHECK-SAME: () #[[ATTR36:[0-9]+]] {
741741
// CHECK-NEXT: entry:
742742
// CHECK-NEXT: ret i32 11
@@ -789,12 +789,12 @@ int caller(void) { return used_def_without_default_decl() + used_decl_without_de
789789
// CHECK-NEXT: ret ptr @fmv_inline._MfcmaMfp16MrdmMsme
790790
// CHECK: resolver_else:
791791
// CHECK-NEXT: [[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
792-
// CHECK-NEXT: [[TMP5:%.*]] = and i64 [[TMP4]], 864726312827224064
793-
// CHECK-NEXT: [[TMP6:%.*]] = icmp eq i64 [[TMP5]], 864726312827224064
792+
// CHECK-NEXT: [[TMP5:%.*]] = and i64 [[TMP4]], 864708720641179648
793+
// CHECK-NEXT: [[TMP6:%.*]] = icmp eq i64 [[TMP5]], 864708720641179648
794794
// CHECK-NEXT: [[TMP7:%.*]] = and i1 true, [[TMP6]]
795795
// CHECK-NEXT: br i1 [[TMP7]], label [[RESOLVER_RETURN1:%.*]], label [[RESOLVER_ELSE2:%.*]]
796796
// CHECK: resolver_return1:
797-
// CHECK-NEXT: ret ptr @fmv_inline._Mmemtag3MmopsMrcpc3
797+
// CHECK-NEXT: ret ptr @fmv_inline._MmemtagMmopsMrcpc3
798798
// CHECK: resolver_else2:
799799
// CHECK-NEXT: [[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
800800
// CHECK-NEXT: [[TMP9:%.*]] = and i64 [[TMP8]], 893353197568
@@ -845,12 +845,12 @@ int caller(void) { return used_def_without_default_decl() + used_decl_without_de
845845
// CHECK-NEXT: ret ptr @fmv_inline._Mbf16Msve
846846
// CHECK: resolver_else14:
847847
// CHECK-NEXT: [[TMP32:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
848-
// CHECK-NEXT: [[TMP33:%.*]] = and i64 [[TMP32]], 268566528
849-
// CHECK-NEXT: [[TMP34:%.*]] = icmp eq i64 [[TMP33]], 268566528
848+
// CHECK-NEXT: [[TMP33:%.*]] = and i64 [[TMP32]], 134348800
849+
// CHECK-NEXT: [[TMP34:%.*]] = icmp eq i64 [[TMP33]], 134348800
850850
// CHECK-NEXT: [[TMP35:%.*]] = and i1 true, [[TMP34]]
851851
// CHECK-NEXT: br i1 [[TMP35]], label [[RESOLVER_RETURN15:%.*]], label [[RESOLVER_ELSE16:%.*]]
852852
// CHECK: resolver_return15:
853-
// CHECK-NEXT: ret ptr @fmv_inline._MditMebf16
853+
// CHECK-NEXT: ret ptr @fmv_inline._Mbf16Mdit
854854
// CHECK: resolver_else16:
855855
// CHECK-NEXT: [[TMP36:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
856856
// CHECK-NEXT: [[TMP37:%.*]] = and i64 [[TMP36]], 20971520

clang/test/CodeGenCXX/attr-target-version.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int __attribute__((target_version("sme-f64f64+bf16"))) foo(int) { return 1; }
55
int __attribute__((target_version("default"))) foo(int) { return 2; }
6-
int __attribute__((target_version("sm4+ebf16"))) foo(void) { return 3; }
6+
int __attribute__((target_version("sm4+bf16"))) foo(void) { return 3; }
77
int __attribute__((target_version("default"))) foo(void) { return 4; }
88

99
struct MyClass {
@@ -84,7 +84,7 @@ int bar() {
8484
// CHECK-NEXT: ret i32 2
8585
//
8686
//
87-
// CHECK-LABEL: define dso_local noundef i32 @_Z3foov._Mebf16Msm4(
87+
// CHECK-LABEL: define dso_local noundef i32 @_Z3foov._Mbf16Msm4(
8888
// CHECK-SAME: ) #[[ATTR2:[0-9]+]] {
8989
// CHECK-NEXT: [[ENTRY:.*:]]
9090
// CHECK-NEXT: ret i32 3
@@ -249,12 +249,12 @@ int bar() {
249249
// CHECK-NEXT: [[RESOLVER_ENTRY:.*:]]
250250
// CHECK-NEXT: call void @__init_cpu_features_resolver()
251251
// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
252-
// CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 268435488
253-
// CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 268435488
252+
// CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 134217760
253+
// CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 134217760
254254
// CHECK-NEXT: [[TMP3:%.*]] = and i1 true, [[TMP2]]
255255
// CHECK-NEXT: br i1 [[TMP3]], label %[[RESOLVER_RETURN:.*]], label %[[RESOLVER_ELSE:.*]]
256256
// CHECK: [[RESOLVER_RETURN]]:
257-
// CHECK-NEXT: ret ptr @_Z3foov._Mebf16Msm4
257+
// CHECK-NEXT: ret ptr @_Z3foov._Mbf16Msm4
258258
// CHECK: [[RESOLVER_ELSE]]:
259259
// CHECK-NEXT: ret ptr @_Z3foov.default
260260
//

clang/test/Sema/aarch64-cpu-supports.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int test_aarch64_features(void) {
1212
if (__builtin_cpu_supports("pmull128"))
1313
return 3;
1414
// expected-warning@+1 {{invalid cpu feature string}}
15-
if (__builtin_cpu_supports("sve2,rpres"))
15+
if (__builtin_cpu_supports("sve2,sve"))
1616
return 4;
1717
// expected-warning@+1 {{invalid cpu feature string}}
1818
if (__builtin_cpu_supports("dgh+sve2-pmull"))

clang/test/Sema/attr-target-clones-aarch64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int __attribute__((target_clones("rng", "fp16fml+fp", "default"))) redecl4(void)
2222
// expected-error@+3 {{'target_clones' attribute does not match previous declaration}}
2323
// expected-note@-2 {{previous declaration is here}}
2424
// expected-warning@+1 {{version list contains entries that don't impact code generation}}
25-
int __attribute__((target_clones("dgh+rpres", "ebf16+dpb", "default"))) redecl4(void) { return 1; }
25+
int __attribute__((target_clones("dgh", "bf16+dpb", "default"))) redecl4(void) { return 1; }
2626

2727
int __attribute__((target_version("flagm2"))) redef2(void) { return 1; }
2828
// expected-error@+2 {{multiversioned function redeclarations require identical target attributes}}
@@ -69,7 +69,7 @@ empty_target_5(void);
6969
void __attribute__((target_clones("sve2-bitperm", "sve2-bitperm")))
7070
dupe_normal(void);
7171

72-
void __attribute__((target_clones("default"), target_clones("memtag3+bti"))) dupe_normal2(void);
72+
void __attribute__((target_clones("default"), target_clones("memtag+bti"))) dupe_normal2(void);
7373

7474
int mv_after_use(void);
7575
int useage(void) {

clang/test/SemaCXX/attr-target-version.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int __attribute__((target_version("flagm2"))) diff_link2(void) { return 1; }
3131
extern int __attribute__((target_version("flagm"))) diff_link2(void);
3232

3333
namespace {
34-
static int __attribute__((target_version("memtag3"))) diff_link2(void) { return 2; }
34+
static int __attribute__((target_version("memtag"))) diff_link2(void) { return 2; }
3535
int __attribute__((target_version("sve2-bitperm"))) diff_link2(void) { return 1; }
3636
} // namespace
3737

compiler-rt/lib/builtins/cpu_model/AArch64CPUFeatures.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ enum CPUFeatures {
5050
FEAT_DGH,
5151
FEAT_I8MM,
5252
FEAT_BF16,
53-
FEAT_EBF16,
54-
FEAT_RPRES,
53+
RESERVED_FEAT_EBF16, // previously used and now ABI legacy
54+
RESERVED_FEAT_RPRES, // previously used and now ABI legacy
5555
FEAT_SVE,
5656
RESERVED_FEAT_SVE_BF16, // previously used and now ABI legacy
5757
RESERVED_FEAT_SVE_EBF16, // previously used and now ABI legacy
@@ -67,7 +67,7 @@ enum CPUFeatures {
6767
FEAT_SME,
6868
RESERVED_FEAT_MEMTAG, // previously used and now ABI legacy
6969
FEAT_MEMTAG2,
70-
FEAT_MEMTAG3,
70+
RESERVED_FEAT_MEMTAG3, // previously used and now ABI legacy
7171
FEAT_SB,
7272
FEAT_PREDRES,
7373
RESERVED_FEAT_SSBS, // previously used and now ABI legacy

compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ static void __init_cpu_features_constructor(unsigned long hwcap,
4545
setCPUFeature(FEAT_SSBS2);
4646
if (hwcap2 & HWCAP2_MTE)
4747
setCPUFeature(FEAT_MEMTAG2);
48-
if (hwcap2 & HWCAP2_MTE3)
49-
setCPUFeature(FEAT_MEMTAG3);
5048
if (hwcap2 & HWCAP2_SVEPMULL)
5149
setCPUFeature(FEAT_SVE_PMULL128);
5250
if (hwcap2 & HWCAP2_SVEBITPERM)
@@ -63,8 +61,6 @@ static void __init_cpu_features_constructor(unsigned long hwcap,
6361
setCPUFeature(FEAT_RNG);
6462
if (hwcap2 & HWCAP2_I8MM)
6563
setCPUFeature(FEAT_I8MM);
66-
if (hwcap2 & HWCAP2_EBF16)
67-
setCPUFeature(FEAT_EBF16);
6864
if (hwcap2 & HWCAP2_DGH)
6965
setCPUFeature(FEAT_DGH);
7066
if (hwcap2 & HWCAP2_FRINT)
@@ -75,8 +71,6 @@ static void __init_cpu_features_constructor(unsigned long hwcap,
7571
setCPUFeature(FEAT_SVE_F64MM);
7672
if (hwcap2 & HWCAP2_BTI)
7773
setCPUFeature(FEAT_BTI);
78-
if (hwcap2 & HWCAP2_RPRES)
79-
setCPUFeature(FEAT_RPRES);
8074
if (hwcap2 & HWCAP2_WFXT)
8175
setCPUFeature(FEAT_WFXT);
8276
if (hwcap2 & HWCAP2_SME)

llvm/include/llvm/TargetParser/AArch64CPUFeatures.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ enum CPUFeatures {
5050
FEAT_DGH,
5151
FEAT_I8MM,
5252
FEAT_BF16,
53-
FEAT_EBF16,
54-
FEAT_RPRES,
53+
RESERVED_FEAT_EBF16, // previously used and now ABI legacy
54+
RESERVED_FEAT_RPRES, // previously used and now ABI legacy
5555
FEAT_SVE,
5656
RESERVED_FEAT_SVE_BF16, // previously used and now ABI legacy
5757
RESERVED_FEAT_SVE_EBF16, // previously used and now ABI legacy
@@ -67,7 +67,7 @@ enum CPUFeatures {
6767
FEAT_SME,
6868
RESERVED_FEAT_MEMTAG, // previously used and now ABI legacy
6969
FEAT_MEMTAG2,
70-
FEAT_MEMTAG3,
70+
RESERVED_FEAT_MEMTAG3, // previously used and now ABI legacy
7171
FEAT_SB,
7272
FEAT_PREDRES,
7373
RESERVED_FEAT_SSBS, // previously used and now ABI legacy

llvm/lib/Target/AArch64/AArch64FMV.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def : FMVExtension<"dit", "FEAT_DIT", "+dit", 180>;
4646
def : FMVExtension<"dotprod", "FEAT_DOTPROD", "+dotprod,+fp-armv8,+neon", 104>;
4747
def : FMVExtension<"dpb", "FEAT_DPB", "+ccpp", 190>;
4848
def : FMVExtension<"dpb2", "FEAT_DPB2", "+ccpp,+ccdp", 200>;
49-
def : FMVExtension<"ebf16", "FEAT_EBF16", "+bf16", 290>;
5049
def : FMVExtension<"f32mm", "FEAT_SVE_F32MM", "+sve,+f32mm,+fullfp16,+fp-armv8,+neon", 350>;
5150
def : FMVExtension<"f64mm", "FEAT_SVE_F64MM", "+sve,+f64mm,+fullfp16,+fp-armv8,+neon", 360>;
5251
def : FMVExtension<"fcma", "FEAT_FCMA", "+fp-armv8,+neon,+complxnum", 220>;
@@ -61,15 +60,13 @@ def : FMVExtension<"jscvt", "FEAT_JSCVT", "+fp-armv8,+neon,+jsconv", 210>;
6160
def : FMVExtension<"ls64", "FEAT_LS64_ACCDATA", "+ls64", 520>;
6261
def : FMVExtension<"lse", "FEAT_LSE", "+lse", 80>;
6362
def : FMVExtension<"memtag", "FEAT_MEMTAG2", "+mte", 440>;
64-
def : FMVExtension<"memtag3", "FEAT_MEMTAG3", "+mte", 460>;
6563
def : FMVExtension<"mops", "FEAT_MOPS", "+mops", 650>;
6664
def : FMVExtension<"predres", "FEAT_PREDRES", "+predres", 480>;
6765
def : FMVExtension<"rcpc", "FEAT_RCPC", "+rcpc", 230>;
6866
def : FMVExtension<"rcpc2", "FEAT_RCPC2", "+rcpc", 240>;
6967
def : FMVExtension<"rcpc3", "FEAT_RCPC3", "+rcpc,+rcpc3", 241>;
7068
def : FMVExtension<"rdm", "FEAT_RDM", "+rdm,+fp-armv8,+neon", 108>;
7169
def : FMVExtension<"rng", "FEAT_RNG", "+rand", 10>;
72-
def : FMVExtension<"rpres", "FEAT_RPRES", "", 300>;
7370
def : FMVExtension<"sb", "FEAT_SB", "+sb", 470>;
7471
def : FMVExtension<"sha2", "FEAT_SHA2", "+sha2,+fp-armv8,+neon", 130>;
7572
def : FMVExtension<"sha3", "FEAT_SHA3", "+sha3,+sha2,+fp-armv8,+neon", 140>;

0 commit comments

Comments
 (0)