From 0fbfedabb9339995a7a8040414aafcc86004b973 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 14 Feb 2023 10:21:06 -0800 Subject: Vacuum unneeded instructions even if children have effects (#5488) This can handle e.g. (drop (i32.add (call ..) (call ..) ) ) We can remove the add and just leave two dropped calls: (drop (call ..) ) (drop (call ..) ) --- src/passes/Vacuum.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 84ae5199c..7c394900d 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -19,6 +19,7 @@ // #include +#include #include #include #include @@ -137,9 +138,17 @@ struct Vacuum : public WalkerPass> { curr = childrenWithEffects[0]; continue; } - // TODO: with multiple children with side effects, we can perhaps figure - // out something clever, like a block with drops, or an i32.add for just - // two, etc. + // The result is not used, but multiple children have side effects, so we + // need to keep them around. We must also return something of the proper + // type - if we can do that, replace everything with the children + a + // dummy value of the proper type. + if (curr->type.isDefaultable()) { + auto* dummy = Builder(*getModule()) + .makeConstantExpression(Literal::makeZeros(curr->type)); + return getDroppedChildrenAndAppend( + curr, *getModule(), getPassOptions(), dummy); + } + // Otherwise, give up. return curr; } } -- cgit v1.2.3