Skip to content

Commit 1a17f2b

Browse files
committed
[WebAssembly] avoid to use explicit disabled feature
In `CoalesceFeaturesAndStripAtomics`, feature string is converted to FeatureBitset and back to feature string. It will lose information about explicit diasbled features.
1 parent c761b4a commit 1a17f2b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ class CoalesceFeaturesAndStripAtomics final : public ModulePass {
200200
bool runOnModule(Module &M) override {
201201
FeatureBitset Features = coalesceFeatures(M);
202202

203-
std::string FeatureStr = getFeatureString(Features);
203+
std::string FeatureStr =
204+
getFeatureString(Features, WasmTM->getTargetFeatureString());
204205
WasmTM->setTargetFeatureString(FeatureStr);
205206
for (auto &F : M)
206207
replaceFeatures(F, FeatureStr);
@@ -238,12 +239,17 @@ class CoalesceFeaturesAndStripAtomics final : public ModulePass {
238239
return Features;
239240
}
240241

241-
std::string getFeatureString(const FeatureBitset &Features) {
242+
static std::string getFeatureString(const FeatureBitset &Features,
243+
StringRef TargetFS) {
242244
std::string Ret;
243245
for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
244246
if (Features[KV.Value])
245247
Ret += (StringRef("+") + KV.Key + ",").str();
246248
}
249+
SubtargetFeatures TF{TargetFS};
250+
for (std::string const &F : TF.getFeatures())
251+
if (!SubtargetFeatures::isEnabled(F))
252+
Ret += F;
247253
return Ret;
248254
}
249255

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mattr=-sign-ext | FileCheck %s
3+
4+
target triple = "wasm32-unknown-unknown"
5+
6+
define i8 @ashr(i8 %v, i8 %x) {
7+
; CHECK-LABEL: ashr:
8+
; CHECK: .functype ashr (i32, i32) -> (i32)
9+
; CHECK-NEXT: # %bb.0:
10+
; CHECK-NEXT: local.get 0
11+
; CHECK-NEXT: i32.const 24
12+
; CHECK-NEXT: i32.shl
13+
; CHECK-NEXT: i32.const 24
14+
; CHECK-NEXT: i32.shr_s
15+
; CHECK-NEXT: local.get 1
16+
; CHECK-NEXT: i32.const 255
17+
; CHECK-NEXT: i32.and
18+
; CHECK-NEXT: i32.shr_s
19+
; CHECK-NEXT: # fallthrough-return
20+
%a = ashr i8 %v, %x
21+
ret i8 %a
22+
}

0 commit comments

Comments
 (0)