From 69f4c1d28585a37ebe8ba53847e78948d11ed8fd Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 19 Apr 2023 16:56:42 -0700 Subject: [PATCH] Disable sign extension in SignExtLowering.cpp (#5676) * 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 --- src/passes/SignExtLowering.cpp | 8 ++++++++ src/passes/pass.cpp | 3 ++- test/lit/help/wasm-opt.test | 3 ++- test/lit/help/wasm2js.test | 3 ++- test/lit/passes/signext-lowering-features.wast | 9 +++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/lit/passes/signext-lowering-features.wast diff --git a/src/passes/SignExtLowering.cpp b/src/passes/SignExtLowering.cpp index 7d03046eabd..beb36494f23 100644 --- a/src/passes/SignExtLowering.cpp +++ b/src/passes/SignExtLowering.cpp @@ -68,6 +68,14 @@ struct SignExtLowering : public WalkerPass> { } } } + + 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(); } diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index d567fee95f9..ff2c7d45fa4 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -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", diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test index ae1768f9faf..2e10ed073ef 100644 --- a/test/lit/help/wasm-opt.test +++ b/test/lit/help/wasm-opt.test @@ -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 diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test index f75d3796576..1766d771dc1 100644 --- a/test/lit/help/wasm2js.test +++ b/test/lit/help/wasm2js.test @@ -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 diff --git a/test/lit/passes/signext-lowering-features.wast b/test/lit/passes/signext-lowering-features.wast new file mode 100644 index 00000000000..fb067158498 --- /dev/null +++ b/test/lit/passes/signext-lowering-features.wast @@ -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)