Skip to content

Commit

Permalink
Disable sign extension in SignExtLowering.cpp (#5676)
Browse files Browse the repository at this point in the history
* Disable sign extension in SignExtLowering.cpp

The sign extension lowering pass would previously lower away the sign extension
instructions, but it wouldn't disable the sign extension feature, so follow-on
passes such as optimize-instructions could reintroduce sign extension
instructions.

Fix the pass to disable the sign extension feature to prevent sign extension
instructions from being reintroduced later.

* update pass description
  • Loading branch information
tlively authored Apr 19, 2023
1 parent 8e965ee commit 1e2e89b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
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)) {
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)

0 comments on commit 1e2e89b

Please sign in to comment.