From 01b126fd79a220d0c7f3be965f8e2889aaef816b Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 19 Apr 2023 08:09:18 -0700 Subject: [PATCH 1/4] 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. --- src/passes/SignExtLowering.cpp | 8 ++++++++ test/lit/passes/signext-lowering-features.wast | 9 +++++++++ 2 files changed, 17 insertions(+) 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/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) From ed169c83fa2469258c8042ed844b64cf4da5b16f Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 19 Apr 2023 08:39:05 -0700 Subject: [PATCH 2/4] update pass description --- src/passes/pass.cpp | 3 ++- test/lit/help/wasm-opt.test | 3 ++- test/lit/help/wasm2js.test | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) 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 From e1d2899ec8100d1d279c060a4055c878b96b656c Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 19 Apr 2023 15:29:37 -0700 Subject: [PATCH 3/4] Disable the memory64 feature in Memory64Lowering.cpp For consistency with other feature lowering passes, disable memory64 in addition to lowering its use away. Although no other passes would introduce new uses of memory64 at the moment, this makes the lowering pass more robust against a future where memory64 might accidentally be reintroduced after being lowered away. --- src/passes/Memory64Lowering.cpp | 8 ++++++++ test/lit/passes/memory64-lowering-features.wast | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/lit/passes/memory64-lowering-features.wast diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp index 661d6cdae8e..194d593d8b8 100644 --- a/src/passes/Memory64Lowering.cpp +++ b/src/passes/Memory64Lowering.cpp @@ -159,6 +159,14 @@ struct Memory64Lowering : public WalkerPass> { } } } + + void run(Module* module) override { + if (!module->features.has(FeatureSet::Memory64)) { + return; + } + super::run(module); + module->features.disable(FeatureSet::Memory64); + } }; Pass* createMemory64LoweringPass() { return new Memory64Lowering(); } diff --git a/test/lit/passes/memory64-lowering-features.wast b/test/lit/passes/memory64-lowering-features.wast new file mode 100644 index 00000000000..d6d7d2b935d --- /dev/null +++ b/test/lit/passes/memory64-lowering-features.wast @@ -0,0 +1,9 @@ +;; RUN: wasm-opt %s --enable-memory64 --print-features --print --memory64-lowering --print-features | filecheck %s + +;; Check that the --signext-lowering pass disables the signext feature. + +;; CHECK: --enable-memory64 +;; CHECK: (module +;; CHECK-NOT: --enable-memory64 + +(module) From aa2db0d61bfa1c45397511000c6827f9f75f7e3f Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 19 Apr 2023 16:02:54 -0700 Subject: [PATCH 4/4] Update test/lit/passes/memory64-lowering-features.wast Co-authored-by: Alon Zakai --- test/lit/passes/memory64-lowering-features.wast | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lit/passes/memory64-lowering-features.wast b/test/lit/passes/memory64-lowering-features.wast index d6d7d2b935d..4c5c1c20791 100644 --- a/test/lit/passes/memory64-lowering-features.wast +++ b/test/lit/passes/memory64-lowering-features.wast @@ -1,6 +1,6 @@ ;; RUN: wasm-opt %s --enable-memory64 --print-features --print --memory64-lowering --print-features | filecheck %s -;; Check that the --signext-lowering pass disables the signext feature. +;; Check that the --memory64-lowering pass disables the signext feature. ;; CHECK: --enable-memory64 ;; CHECK: (module