diff options
author | Nikita Popov <npopov@redhat.com> | 2024-10-15 09:34:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-15 09:34:55 +0200 |
commit | 5a7b79c93e2e0c71aec016973f5f13d3bb2e7a62 (patch) | |
tree | 9d21b96a3d169bf4245cf79fdddd0323e5aa232c /llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | |
parent | c180da93e0257a92b0bb428f70c1b0de083ebf72 (diff) | |
download | llvm-5a7b79c93e2e0c71aec016973f5f13d3bb2e7a62.zip llvm-5a7b79c93e2e0c71aec016973f5f13d3bb2e7a62.tar.gz llvm-5a7b79c93e2e0c71aec016973f5f13d3bb2e7a62.tar.bz2 |
[WebAssembly] Fix feature coalescing (#110647)
This fixes a problem introduced in #80094. That PR copied negative
features from the TargetMachine to the end of the feature string. This
is not correct, because even if we have a baseline TM of say `-simd128`,
but a function with `+simd128`, the coalesced feature string should have
`+simd128`, not `-simd128`.
To address the original motivation of that PR, we should instead
explicitly materialize the negative features in the target feature
string, so that explicitly disabled default features are honored.
Unfortunately, there doesn't seem to be any way to actually test this
using llc, because `-mattr` appends the specified features to the end of
the `"target-features"` attribute. I've tested this locally by making it
prepend the features instead.
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 7b7ba0b..3fe6ccf 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -205,8 +205,7 @@ public: bool runOnModule(Module &M) override { FeatureBitset Features = coalesceFeatures(M); - std::string FeatureStr = - getFeatureString(Features, WasmTM->getTargetFeatureString()); + std::string FeatureStr = getFeatureString(Features); WasmTM->setTargetFeatureString(FeatureStr); for (auto &F : M) replaceFeatures(F, FeatureStr); @@ -244,17 +243,14 @@ private: return Features; } - static std::string getFeatureString(const FeatureBitset &Features, - StringRef TargetFS) { + static std::string getFeatureString(const FeatureBitset &Features) { std::string Ret; for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) { if (Features[KV.Value]) Ret += (StringRef("+") + KV.Key + ",").str(); + else + Ret += (StringRef("-") + KV.Key + ",").str(); } - SubtargetFeatures TF{TargetFS}; - for (std::string const &F : TF.getFeatures()) - if (!SubtargetFeatures::isEnabled(F)) - Ret += F + ","; return Ret; } |