Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable sign extension in SignExtLowering.cpp #5676

Merged
merged 2 commits into from
Apr 19, 2023
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
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
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
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
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)