Skip to content

Commit b0378e7

Browse files
authored
[AArch64TargetParser]Fix reconstructFromParsedFeatures ignoring negative features (#142236)
The `targetFeatureToExtension` function used by reconstructFromParsedFeatures only found positive `+FEATURE` strings, but not negative `-FEATURE` strings. Extend the function to handle both to fix `reconstructFromParsedFeatures`.
1 parent 2578122 commit b0378e7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -triple aarch64-- -target-feature +neon -target-feature +sve\
2+
// RUN: -target-feature -sve -emit-llvm %s -o - | FileCheck %s
3+
4+
// Reproducer for bug where clang would reject always_inline for unrelated
5+
// target features if they were disable with `-feature` on the command line.
6+
// CHECK: @bar
7+
__attribute__((always_inline)) __attribute__((target("neon"))) void foo() {}
8+
void bar() { foo(); }

llvm/lib/TargetParser/AArch64TargetParser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ uint64_t AArch64::getFMVPriority(ArrayRef<StringRef> Features) {
6060
ExtensionSet FeatureBits;
6161
for (const StringRef Feature : Features) {
6262
std::optional<FMVInfo> FMV = parseFMVExtension(Feature);
63-
if (!FMV) {
63+
if (!FMV && Feature.starts_with('+')) {
6464
if (std::optional<ExtensionInfo> Info = targetFeatureToExtension(Feature))
6565
FMV = lookupFMVByID(Info->ID);
6666
}
@@ -181,7 +181,8 @@ std::optional<AArch64::FMVInfo> AArch64::parseFMVExtension(StringRef FMVExt) {
181181
std::optional<AArch64::ExtensionInfo>
182182
AArch64::targetFeatureToExtension(StringRef TargetFeature) {
183183
for (const auto &E : Extensions)
184-
if (TargetFeature == E.PosTargetFeature)
184+
if (TargetFeature == E.PosTargetFeature ||
185+
TargetFeature == E.NegTargetFeature)
185186
return E;
186187
return {};
187188
}

llvm/unittests/TargetParser/TargetParserTest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,22 @@ TEST_P(AArch64ExtensionDependenciesBaseCPUTestFixture,
18311831
}
18321832
}
18331833

1834+
TEST(TargetParserTest, testAArch64ReconstructFromParsedFeatures) {
1835+
AArch64::ExtensionSet Extensions;
1836+
std::vector<std::string> FeatureOptions = {
1837+
"-sve2", "-Baz", "+sve", "+FooBar", "+sve2", "+neon", "-sve",
1838+
};
1839+
std::vector<std::string> NonExtensions;
1840+
Extensions.reconstructFromParsedFeatures(FeatureOptions, NonExtensions);
1841+
1842+
std::vector<std::string> NonExtensionsExpected = {"-Baz", "+FooBar"};
1843+
ASSERT_THAT(NonExtensions, testing::ContainerEq(NonExtensionsExpected));
1844+
std::vector<StringRef> Features;
1845+
Extensions.toLLVMFeatureList(Features);
1846+
std::vector<StringRef> FeaturesExpected = {"+neon", "-sve", "+sve2"};
1847+
ASSERT_THAT(Features, testing::ContainerEq(FeaturesExpected));
1848+
}
1849+
18341850
AArch64ExtensionDependenciesBaseArchTestParams
18351851
AArch64ExtensionDependenciesArchData[] = {
18361852
// Base architecture features

0 commit comments

Comments
 (0)