diff options
author | Alon Zakai <azakai@google.com> | 2023-05-30 17:07:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-30 17:07:28 -0700 |
commit | 3b0b011b36797388a379da85b11e55830906cf0d (patch) | |
tree | 0d4a3110a8fe9304130fc012e330a870088890b0 /src | |
parent | 26ad3ffc326d54f893eee3f1d520b8f4c1cbfe11 (diff) | |
download | binaryen-3b0b011b36797388a379da85b11e55830906cf0d.tar.gz binaryen-3b0b011b36797388a379da85b11e55830906cf0d.tar.bz2 binaryen-3b0b011b36797388a379da85b11e55830906cf0d.zip |
StackIR: Remove nops (#5746)
No nop instruction is necessary in wasm, so in StackIR we can simply
remove them all.
Fixes #5745
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/StackIR.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/passes/StackIR.cpp b/src/passes/StackIR.cpp index bbce6bae8..438ed8b55 100644 --- a/src/passes/StackIR.cpp +++ b/src/passes/StackIR.cpp @@ -73,6 +73,7 @@ public: } removeUnneededBlocks(); dce(); + vacuum(); } private: @@ -100,6 +101,22 @@ private: } } + // Remove obviously-unneeded code. + void vacuum() { + // In the wasm binary format a nop is never needed. (In Binaryen IR, in + // comparison, it is necessary e.g. in a function body or an if arm.) + // + // It is especially important to remove nops because we add nops when we + // read wasm into Binaryen IR. That is, this avoids a potential increase in + // code size. + for (Index i = 0; i < insts.size(); i++) { + auto*& inst = insts[i]; + if (inst && inst->origin->is<Nop>()) { + inst = nullptr; + } + } + } + // If ordered properly, we can avoid a local.set/local.get pair, // and use the value directly from the stack, for example // [..produce a value on the stack..] |