Skip to content

Commit 16cd344

Browse files
authored
[RISCV] Fix collectNonISAExtFeature returning negative extension features (#76962)
collectNonISAExtFeature was returning any negative extension features, e.g. given an input of +zifencei,+m,+a,+save-restore,-zbb,-relax,-zfa It would return +save-restore,-zbb,-relax,-zfa Because negative extensions aren't emitted when calling toFeatureVector(), and so were considered missing. Hence why we still see "-zfa" and "-zfb" in the tests for the full arch string attributes, even though with a full arch string we should be overriding the extensions. This fixes it by using RISCVISAInfo::isSupportedExtensionFeature instead to check if a feature is an ISA extension.
1 parent 97e3220 commit 16cd344

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,15 @@ ArrayRef<Builtin::Info> RISCVTargetInfo::getTargetBuiltins() const {
237237

238238
static std::vector<std::string>
239239
collectNonISAExtFeature(ArrayRef<std::string> FeaturesNeedOverride, int XLen) {
240-
auto ParseResult =
241-
llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesNeedOverride);
242-
243-
if (!ParseResult) {
244-
consumeError(ParseResult.takeError());
245-
return std::vector<std::string>();
246-
}
247-
248-
std::vector<std::string> ImpliedFeatures = (*ParseResult)->toFeatureVector();
249-
250240
std::vector<std::string> NonISAExtFeatureVec;
251241

242+
auto IsNonISAExtFeature = [](const std::string &Feature) {
243+
assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-'));
244+
StringRef Ext = StringRef(Feature).drop_front(); // drop the +/-
245+
return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext);
246+
};
252247
llvm::copy_if(FeaturesNeedOverride, std::back_inserter(NonISAExtFeatureVec),
253-
[&](const std::string &Feat) {
254-
return !llvm::is_contained(ImpliedFeatures, Feat);
255-
});
248+
IsNonISAExtFeature);
256249

257250
return NonISAExtFeatureVec;
258251
}

clang/test/CodeGen/RISCV/riscv-func-attr-target.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ __attribute__((target("cpu=sifive-u54"))) void testAttrCpuOnly() {}
4040
// CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" "target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zbb,-zfa" "tune-cpu"="generic-rv64" }
4141
// CHECK: attributes #2 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,-relax,-zfa" }
4242
// CHECK: attributes #3 = { {{.*}}"target-features"="+64bit,+a,+d,+experimental-zicond,+f,+m,+save-restore,+v,+zbb,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa" }
43-
// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,-relax,-zfa" }
44-
// CHECK: attributes #5 = { {{.*}}"target-features"="+64bit,+m,+save-restore,-relax,-zbb,-zfa" }
43+
// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,-relax" }
44+
// CHECK: attributes #5 = { {{.*}}"target-features"="+64bit,+m,+save-restore,-relax" }
4545
// CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,-relax,-zfa" }
46-
// CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+m,+save-restore,-relax,-zbb,-zfa" }
47-
// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zicsr,+zifencei,-relax,-zbb,-zfa" }
46+
// CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+m,+save-restore,-relax" }
47+
// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zicsr,+zifencei,-relax" }

0 commit comments

Comments
 (0)