Skip to content

Commit d8bffa9

Browse files
authored
Revert "[AArch64][AsmParser] Directives should clear transitively implied features (#106625)" (#106813)
Revert #106625 and fix attempt #106804" There is another issue in https://lab.llvm.org/buildbot/#/builders/169/builds/2690 directive-cpu-err.s and the fix like #106804 fixed the overflow but fails CHECKs. This reverts commit 10affaf. This reverts commit 2497739.
1 parent 0ab3d6e commit d8bffa9

File tree

6 files changed

+59
-84
lines changed

6 files changed

+59
-84
lines changed

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

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6947,22 +6947,18 @@ static void ExpandCryptoAEK(const AArch64::ArchInfo &ArchInfo,
69476947
}
69486948
}
69496949

6950-
static SMLoc incrementLoc(SMLoc L, int Offset) {
6951-
return SMLoc::getFromPointer(L.getPointer() + Offset);
6952-
}
6953-
69546950
/// parseDirectiveArch
69556951
/// ::= .arch token
69566952
bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
6957-
SMLoc CurLoc = getLoc();
6953+
SMLoc ArchLoc = getLoc();
69586954

69596955
StringRef Arch, ExtensionString;
69606956
std::tie(Arch, ExtensionString) =
69616957
getParser().parseStringToEndOfStatement().trim().split('+');
69626958

69636959
const AArch64::ArchInfo *ArchInfo = AArch64::parseArch(Arch);
69646960
if (!ArchInfo)
6965-
return Error(CurLoc, "unknown arch name");
6961+
return Error(ArchLoc, "unknown arch name");
69666962

69676963
if (parseToken(AsmToken::EndOfStatement))
69686964
return true;
@@ -6982,30 +6978,27 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
69826978
ExtensionString.split(RequestedExtensions, '+');
69836979

69846980
ExpandCryptoAEK(*ArchInfo, RequestedExtensions);
6985-
CurLoc = incrementLoc(CurLoc, Arch.size());
69866981

6982+
FeatureBitset Features = STI.getFeatureBits();
6983+
setAvailableFeatures(ComputeAvailableFeatures(Features));
69876984
for (auto Name : RequestedExtensions) {
6988-
// Advance source location past '+'.
6989-
CurLoc = incrementLoc(CurLoc, 1);
6990-
69916985
bool EnableFeature = !Name.consume_front_insensitive("no");
69926986

6993-
auto It = llvm::find_if(ExtensionMap, [&Name](const auto &Extension) {
6994-
return Extension.Name == Name;
6995-
});
6996-
6997-
if (It == std::end(ExtensionMap))
6998-
return Error(CurLoc, "unsupported architectural extension: " + Name);
6987+
for (const auto &Extension : ExtensionMap) {
6988+
if (Extension.Name != Name)
6989+
continue;
69996990

7000-
if (EnableFeature)
7001-
STI.SetFeatureBitsTransitively(It->Features);
7002-
else
7003-
STI.ClearFeatureBitsTransitively(It->Features);
6991+
if (Extension.Features.none())
6992+
report_fatal_error("unsupported architectural extension: " + Name);
70046993

7005-
CurLoc = incrementLoc(CurLoc, Name.size());
6994+
FeatureBitset ToggleFeatures =
6995+
EnableFeature
6996+
? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
6997+
: STI.ToggleFeature(Features & Extension.Features);
6998+
setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
6999+
break;
7000+
}
70067001
}
7007-
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
7008-
setAvailableFeatures(Features);
70097002
return false;
70107003
}
70117004

@@ -7025,21 +7018,28 @@ bool AArch64AsmParser::parseDirectiveArchExtension(SMLoc L) {
70257018
Name = Name.substr(2);
70267019
}
70277020

7028-
auto It = llvm::find_if(ExtensionMap, [&Name](const auto &Extension) {
7029-
return Extension.Name == Name;
7030-
});
7021+
MCSubtargetInfo &STI = copySTI();
7022+
FeatureBitset Features = STI.getFeatureBits();
7023+
for (const auto &Extension : ExtensionMap) {
7024+
if (Extension.Name != Name)
7025+
continue;
7026+
7027+
if (Extension.Features.none())
7028+
return Error(ExtLoc, "unsupported architectural extension: " + Name);
7029+
7030+
FeatureBitset ToggleFeatures =
7031+
EnableFeature
7032+
? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
7033+
: STI.ToggleFeature(Features & Extension.Features);
7034+
setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
7035+
return false;
7036+
}
70317037

7032-
if (It == std::end(ExtensionMap))
7033-
return Error(ExtLoc, "unsupported architectural extension: " + Name);
7038+
return Error(ExtLoc, "unknown architectural extension: " + Name);
7039+
}
70347040

7035-
MCSubtargetInfo &STI = copySTI();
7036-
if (EnableFeature)
7037-
STI.SetFeatureBitsTransitively(It->Features);
7038-
else
7039-
STI.ClearFeatureBitsTransitively(It->Features);
7040-
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
7041-
setAvailableFeatures(Features);
7042-
return false;
7041+
static SMLoc incrementLoc(SMLoc L, int Offset) {
7042+
return SMLoc::getFromPointer(L.getPointer() + Offset);
70437043
}
70447044

70457045
/// parseDirectiveCPU
@@ -7075,22 +7075,30 @@ bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
70757075

70767076
bool EnableFeature = !Name.consume_front_insensitive("no");
70777077

7078-
auto It = llvm::find_if(ExtensionMap, [&Name](const auto &Extension) {
7079-
return Extension.Name == Name;
7080-
});
7078+
bool FoundExtension = false;
7079+
for (const auto &Extension : ExtensionMap) {
7080+
if (Extension.Name != Name)
7081+
continue;
70817082

7082-
if (It == std::end(ExtensionMap))
7083-
Error(CurLoc, "unsupported architectural extension: " + Name);
7083+
if (Extension.Features.none())
7084+
report_fatal_error("unsupported architectural extension: " + Name);
70847085

7085-
if (EnableFeature)
7086-
STI.SetFeatureBitsTransitively(It->Features);
7087-
else
7088-
STI.ClearFeatureBitsTransitively(It->Features);
7086+
FeatureBitset Features = STI.getFeatureBits();
7087+
FeatureBitset ToggleFeatures =
7088+
EnableFeature
7089+
? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
7090+
: STI.ToggleFeature(Features & Extension.Features);
7091+
setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
7092+
FoundExtension = true;
7093+
7094+
break;
7095+
}
7096+
7097+
if (!FoundExtension)
7098+
Error(CurLoc, "unsupported architectural extension");
70897099

70907100
CurLoc = incrementLoc(CurLoc, Name.size());
70917101
}
7092-
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
7093-
setAvailableFeatures(Features);
70947102
return false;
70957103
}
70967104

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

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// RUN: not llvm-mc -triple aarch64 -filetype asm -o - %s 2>&1 | FileCheck %s
22

3-
.arch_extension sve2+nosve
3+
.arch_extension nosve
44

55
ptrue p0.b, pow2
66
// CHECK: error: instruction requires: sve or sme
77
// CHECK-NEXT: ptrue p0.b, pow2
8-
9-
// Check that setting +nosve implies +nosve2
10-
adclb z0.s, z1.s, z31.s
11-
// CHECK: error: instruction requires: sve2
12-
// CHECK-NEXT: adclb z0.s, z1.s, z31.s
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// RUN: not llvm-mc -triple aarch64 -filetype asm -o - %s 2>&1 | FileCheck %s
22

3-
.cpu generic+sve2+nosve
3+
.cpu generic+sve+nosve
44
ptrue p0.b, pow2
55
// CHECK: error: instruction requires: sve or sme
66
// CHECK-NEXT: ptrue p0.b, pow2
7-
8-
// Check that setting +nosve implies +nosve2
9-
adclb z0.s, z1.s, z31.s
10-
// CHECK: error: instruction requires: sve2
11-
// CHECK-NEXT: adclb z0.s, z1.s, z31.s

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
# CHECK-NEXT: aese v0.8h, v1.8h
1313
# CHECK-NEXT: ^
1414

15+
// We silently ignore invalid features.
1516
.arch armv8+foo
1617
aese v0.8h, v1.8h
1718

18-
# CHECK: error: unsupported architectural extension: foo
19-
# CHECK-NEXT: .arch armv8+foo
20-
# CHECK-NEXT: ^
21-
2219
# CHECK: error: invalid operand for instruction
2320
# CHECK-NEXT: aese v0.8h, v1.8h
2421
# CHECK-NEXT: ^

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: -filetype asm -o - %s 2>&1 | FileCheck %s
55

66
.arch_extension axp64
7-
// CHECK: error: unsupported architectural extension: axp64
7+
// CHECK: error: unknown architectural extension: axp64
88
// CHECK-NEXT: .arch_extension axp64
99

1010
crc32cx w0, w1, x3
@@ -49,8 +49,6 @@ fminnm d0, d0, d1
4949
// CHECK: [[@LINE-1]]:1: error: instruction requires: fp
5050
// CHECK-NEXT: fminnm d0, d0, d1
5151

52-
// nofp implied nosimd, so reinstate it
53-
.arch_extension simd
5452
addp v0.4s, v0.4s, v0.4s
5553
// CHECK-NOT: [[@LINE-1]]:1: error: instruction requires: neon
5654
.arch_extension nosimd
@@ -72,8 +70,6 @@ casa w5, w7, [x20]
7270
// CHECK: [[@LINE-1]]:1: error: instruction requires: lse
7371
// CHECK-NEXT: casa w5, w7, [x20]
7472

75-
// nolse implied nolse128, so reinstate it
76-
.arch_extension lse128
7773
swpp x0, x2, [x3]
7874
// CHECK-NOT: [[@LINE-1]]:1: error: instruction requires: lse128
7975
.arch_extension nolse128
@@ -88,8 +84,6 @@ cfp rctx, x0
8884
// CHECK: [[@LINE-1]]:5: error: CFPRCTX requires: predres
8985
// CHECK-NEXT: cfp rctx, x0
9086

91-
// nopredres implied nopredres2, so reinstate it
92-
.arch_extension predres2
9387
cosp rctx, x0
9488
// CHECK-NOT: [[@LINE-1]]:6: error: COSP requires: predres2
9589
.arch_extension nopredres2
@@ -139,8 +133,6 @@ ldapr x0, [x1]
139133
// CHECK: [[@LINE-1]]:1: error: instruction requires: rcpc
140134
// CHECK-NEXT: ldapr x0, [x1]
141135

142-
// norcpc implied norcpc3, so reinstate it
143-
.arch_extension rcpc3
144136
stilp w24, w0, [x16, #-8]!
145137
// CHECK-NOT: [[@LINE-1]]:1: error: instruction requires: rcpc3
146138
.arch_extension norcpc3
@@ -177,8 +169,6 @@ cpyfp [x0]!, [x1]!, x2!
177169
// CHECK: [[@LINE-1]]:1: error: instruction requires: mops
178170
// CHECK-NEXT: cpyfp [x0]!, [x1]!, x2!
179171

180-
// nolse128 implied nod128, so reinstate it
181-
.arch_extension d128
182172
// This needs to come before `.arch_extension nothe` as it uses an instruction
183173
// that requires both the and d128
184174
sysp #0, c2, c0, #0, x0, x1
@@ -214,8 +204,6 @@ umax x0, x1, x2
214204
// CHECK: [[@LINE-1]]:1: error: instruction requires: cssc
215205
// CHECK-NEXT: umax x0, x1, x2
216206

217-
// noras implied norasv2, so reinstate it
218-
.arch_extension rasv2
219207
mrs x0, ERXGSR_EL1
220208
// CHECK-NOT: [[@LINE-1]]:9: error: expected readable system register
221209
.arch_extension norasv2

0 commit comments

Comments
 (0)