Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "llvm/TargetParser/X86TargetParser.h"
#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include <optional>
#include <set>

using namespace clang;
using namespace CodeGen;
Expand Down Expand Up @@ -2763,9 +2764,10 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD,
Attrs.addAttribute("fmv-features");
AddedAttr = true;
} else if (!Feats.empty()) {
llvm::sort(Feats);
// Sort features and remove duplicates.
std::set<StringRef> OrderedFeats(Feats.begin(), Feats.end());
std::string FMVFeatures;
for (StringRef F : Feats)
for (StringRef F : OrderedFeats)
FMVFeatures.append("," + F.str());
Attrs.addAttribute("fmv-features", FMVFeatures.substr(1));
AddedAttr = true;
Expand Down Expand Up @@ -2808,6 +2810,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD,
llvm::AttributeMask RemoveAttrs;
RemoveAttrs.addAttribute("target-cpu");
RemoveAttrs.addAttribute("target-features");
RemoveAttrs.addAttribute("fmv-features");
RemoveAttrs.addAttribute("tune-cpu");
F->removeFnAttrs(RemoveAttrs);
F->addFnAttrs(Attrs);
Expand Down
6 changes: 3 additions & 3 deletions clang/test/CodeGen/AArch64/fmv-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ __attribute__((target_version("sve2-sm4"))) int fmv(void) { return 0; }
// CHECK: define dso_local i32 @fmv._Mwfxt() #[[wfxt:[0-9]+]] {
__attribute__((target_version("wfxt"))) int fmv(void) { return 0; }

// CHECK: define dso_local i32 @fmv._MaesMbf16MbtiMcrc() #[[multiple_features:[0-9]+]] {
__attribute__((target_version("aes+bf16+bti+crc"))) int fmv(void) { return 0; }
// CHECK: define dso_local i32 @fmv._MaesMbf16MbtiMcrc() #[[unordered_features_with_duplicates:[0-9]+]] {
__attribute__((target_version("crc+bti+bti+bti+aes+aes+bf16"))) int fmv(void) { return 0; }

// CHECK-NOT: define dso_local i32 @fmv._M{{.*}}
__attribute__((target_version("non_existent_extension"))) int fmv(void);
Expand Down Expand Up @@ -198,5 +198,5 @@ int caller() {
// CHECK: attributes #[[sve2_sha3]] = {{.*}} "fmv-features"="sve2-sha3"
// CHECK: attributes #[[sve2_sm4]] = {{.*}} "fmv-features"="sve2-sm4"
// CHECK: attributes #[[wfxt]] = {{.*}} "fmv-features"="wfxt"
// CHECK: attributes #[[multiple_features]] = {{.*}} "fmv-features"="aes,bf16,bti,crc"
// CHECK: attributes #[[unordered_features_with_duplicates]] = {{.*}} "fmv-features"="aes,bf16,bti,crc"
// CHECK: attributes #[[default]] = {{.*}} "fmv-features"
Loading