Skip to content

Commit c82054b

Browse files
HerrCai0907Carlos Gálvez
authored and
Carlos Gálvez
committed
[WebAssembly] avoid to enable explicit disabled feature (llvm#80094)
1 parent debc9d6 commit c82054b

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mattr=-sign-ext,-bulk-memory | FileCheck %s
3+
4+
target triple = "wasm32-unknown-unknown"
5+
6+
define i8 @not_use_extend8_s(i8 %v, i8 %x) {
7+
; CHECK-LABEL: not_use_extend8_s:
8+
; CHECK: .functype not_use_extend8_s (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+
}
23+
24+
attributes #0 = { "target-features"="+bulk-memory," }
25+
26+
declare void @llvm.memset.p0.i32(ptr, i8, i32, i1)
27+
28+
define void @lower_bulk_memory(i8 %val) #0 {
29+
; CHECK-LABEL: lower_bulk_memory:
30+
; CHECK: .functype lower_bulk_memory (i32) -> ()
31+
; CHECK-NEXT: .local i32
32+
; CHECK-NEXT: # %bb.0:
33+
; CHECK-NEXT: global.get __stack_pointer
34+
; CHECK-NEXT: i32.const 112
35+
; CHECK-NEXT: i32.sub
36+
; CHECK-NEXT: local.tee 1
37+
; CHECK-NEXT: global.set __stack_pointer
38+
; CHECK-NEXT: local.get 1
39+
; CHECK-NEXT: i32.const 12
40+
; CHECK-NEXT: i32.add
41+
; CHECK-NEXT: local.get 0
42+
; CHECK-NEXT: i32.const 100
43+
; CHECK-NEXT: call memset
44+
; CHECK-NEXT: drop
45+
; CHECK-NEXT: local.get 1
46+
; CHECK-NEXT: i32.const 112
47+
; CHECK-NEXT: i32.add
48+
; CHECK-NEXT: global.set __stack_pointer
49+
; CHECK-NEXT: # fallthrough-return
50+
%a = alloca [100 x i8]
51+
call void @llvm.memset.p0.i32(ptr %a, i8 %val, i32 100, i1 false)
52+
ret void
53+
}

0 commit comments

Comments
 (0)