Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/passes/SignExtLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ struct SignExtLowering : public WalkerPass<PostWalker<SignExtLowering>> {
}
}
}

void run(Module* module) override {
if (!module->features.has(FeatureSet::SignExt)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible the module could contain sign ext instructions but this feature not be enabled? (I guess in that case it would not validate?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder why the test we have in emscripten for this was passing.. investigating.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emscripten test merely checks that --signext-lowering is part of the wasm-opt command line .. I didn't both to actually decompile the module to verify binaryen was actually doing the right thing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible the module could contain sign ext instructions but this feature not be enabled? (I guess in that case it would not validate?)

Right, in this case the module would not validate and Binaryen would produce an error.

return;
}
super::run(module);
module->features.disable(FeatureSet::SignExt);
}
};

Pass* createSignExtLoweringPass() { return new SignExtLowering(); }
Expand Down
3 changes: 2 additions & 1 deletion src/passes/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ void PassRegistry::registerPasses() {
"apply more specific subtypes to signature types where possible",
createSignatureRefiningPass);
registerPass("signext-lowering",
"lower sign-ext operations to wasm mvp",
"lower sign-ext operations to wasm mvp and disable the sign "
"extension feature",
createSignExtLoweringPass);
registerPass("simplify-globals",
"miscellaneous globals-related optimizations",
Expand Down
3 changes: 2 additions & 1 deletion test/lit/help/wasm-opt.test
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@
;; CHECK-NEXT: signature types where possible
;; CHECK-NEXT:
;; CHECK-NEXT: --signext-lowering lower sign-ext operations to
;; CHECK-NEXT: wasm mvp
;; CHECK-NEXT: wasm mvp and disable the sign
;; CHECK-NEXT: extension feature
;; CHECK-NEXT:
;; CHECK-NEXT: --simplify-globals miscellaneous globals-related
;; CHECK-NEXT: optimizations
Expand Down
3 changes: 2 additions & 1 deletion test/lit/help/wasm2js.test
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@
;; CHECK-NEXT: signature types where possible
;; CHECK-NEXT:
;; CHECK-NEXT: --signext-lowering lower sign-ext operations to
;; CHECK-NEXT: wasm mvp
;; CHECK-NEXT: wasm mvp and disable the sign
;; CHECK-NEXT: extension feature
;; CHECK-NEXT:
;; CHECK-NEXT: --simplify-globals miscellaneous globals-related
;; CHECK-NEXT: optimizations
Expand Down
9 changes: 9 additions & 0 deletions test/lit/passes/signext-lowering-features.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
;; RUN: wasm-opt %s --enable-sign-ext --print-features --print --signext-lowering --print-features | filecheck %s

;; Check that the --signext-lowering pass disables the signext feature.

;; CHECK: --enable-sign-ext
;; CHECK: (module
;; CHECK-NOT: --enable-sign-ext

(module)