Skip to content

Commit ff3f3a5

Browse files
committed
[AArch64][AsmParser] Arch directives should set implied features.
When assembling for example an SVE instruction with the `.arch +sve2` directive, +sve should be implied by setting +sve2, similar to what would happen if one would pass the mattr=+sve2 flag on the command-line. The AsmParser doesn't set the implied features, meaning that the SVE instruction does not assemble. This patch fixes that. Note that the same does not hold when disabling a feature. For example, +nosve2 does not imply +nosve. Reviewed By: c-rhodes Differential Revision: https://reviews.llvm.org/D120259
1 parent dbc4d28 commit ff3f3a5

File tree

5 files changed

+55
-19
lines changed

5 files changed

+55
-19
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6214,12 +6214,11 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
62146214
if (Extension.Features.none())
62156215
report_fatal_error("unsupported architectural extension: " + Name);
62166216

6217-
FeatureBitset ToggleFeatures = EnableFeature
6218-
? (~Features & Extension.Features)
6219-
: ( Features & Extension.Features);
6220-
FeatureBitset Features =
6221-
ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
6222-
setAvailableFeatures(Features);
6217+
FeatureBitset ToggleFeatures =
6218+
EnableFeature
6219+
? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
6220+
: STI.ToggleFeature(Features & Extension.Features);
6221+
setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
62236222
break;
62246223
}
62256224
}
@@ -6252,12 +6251,11 @@ bool AArch64AsmParser::parseDirectiveArchExtension(SMLoc L) {
62526251
if (Extension.Features.none())
62536252
return Error(ExtLoc, "unsupported architectural extension: " + Name);
62546253

6255-
FeatureBitset ToggleFeatures = EnableFeature
6256-
? (~Features & Extension.Features)
6257-
: (Features & Extension.Features);
6258-
FeatureBitset Features =
6259-
ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
6260-
setAvailableFeatures(Features);
6254+
FeatureBitset ToggleFeatures =
6255+
EnableFeature
6256+
? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
6257+
: STI.ToggleFeature(Features & Extension.Features);
6258+
setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
62616259
return false;
62626260
}
62636261

@@ -6297,7 +6295,6 @@ bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
62976295

62986296
ExpandCryptoAEK(llvm::AArch64::getCPUArchKind(CPU), RequestedExtensions);
62996297

6300-
FeatureBitset Features = STI.getFeatureBits();
63016298
for (auto Name : RequestedExtensions) {
63026299
// Advance source location past '+'.
63036300
CurLoc = incrementLoc(CurLoc, 1);
@@ -6317,12 +6314,12 @@ bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
63176314
if (Extension.Features.none())
63186315
report_fatal_error("unsupported architectural extension: " + Name);
63196316

6320-
FeatureBitset ToggleFeatures = EnableFeature
6321-
? (~Features & Extension.Features)
6322-
: ( Features & Extension.Features);
6323-
FeatureBitset Features =
6324-
ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
6325-
setAvailableFeatures(Features);
6317+
FeatureBitset Features = STI.getFeatureBits();
6318+
FeatureBitset ToggleFeatures =
6319+
EnableFeature
6320+
? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
6321+
: STI.ToggleFeature(Features & Extension.Features);
6322+
setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
63266323
FoundExtension = true;
63276324

63286325
break;

llvm/test/MC/AArch64/SVE/directive-arch.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44

55
ptrue p0.b, pow2
66
// CHECK: ptrue p0.b, pow2
7+
8+
// Test that the implied +sve feature is also set from +sve2.
9+
.arch armv8-a+sve2
10+
11+
ptrue p0.b, pow2
12+
// CHECK: ptrue p0.b, pow2

llvm/test/MC/AArch64/SVE/directive-arch_extension.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@
44

55
ptrue p0.b, pow2
66
// CHECK: ptrue p0.b, pow2
7+
8+
// Test that the implied +sve feature is also set from +sve2.
9+
.arch_extension nosve
10+
.arch_extension sve2
11+
ptrue p0.b, pow2
12+
// CHECK: ptrue p0.b, pow2
13+
14+
// Check that setting +nosve2 does not imply +nosve
15+
.arch_extension nosve2
16+
17+
ptrue p0.b, pow2
18+
// CHECK: ptrue p0.b, pow2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: not llvm-mc -triple aarch64 -filetype asm -o - %s 2>&1 | FileCheck %s
2+
3+
.cpu generic+sve+nosve
4+
ptrue p0.b, pow2
5+
// CHECK: error: instruction requires: sve or sme
6+
// CHECK-NEXT: ptrue p0.b, pow2
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: llvm-mc -triple=aarch64 < %s | FileCheck %s
2+
3+
.cpu generic+sve
4+
ptrue p0.b, pow2
5+
// CHECK: ptrue p0.b, pow2
6+
7+
// Test that the implied +sve feature is also set from +sve2.
8+
.cpu generic+sve2
9+
ptrue p0.b, pow2
10+
// CHECK: ptrue p0.b, pow2
11+
12+
// Check that setting +nosve2 does not imply +nosve
13+
.cpu generic+sve2+nosve2
14+
ptrue p0.b, pow2
15+
// CHECK: ptrue p0.b, pow2

0 commit comments

Comments
 (0)