diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/ordering.h | 10 | ||||
-rw-r--r-- | src/passes/GlobalTypeOptimization.cpp | 18 |
2 files changed, 18 insertions, 10 deletions
diff --git a/src/ir/ordering.h b/src/ir/ordering.h index 55163759c..ed2c00ee2 100644 --- a/src/ir/ordering.h +++ b/src/ir/ordering.h @@ -34,11 +34,11 @@ namespace wasm { // // (temp = first, second, temp) // -Expression* getResultOfFirst(Expression* first, - Expression* second, - Function* func, - Module* wasm, - const PassOptions& passOptions) { +inline Expression* getResultOfFirst(Expression* first, + Expression* second, + Function* func, + Module* wasm, + const PassOptions& passOptions) { assert(first->type.isConcrete()); Builder builder(*wasm); diff --git a/src/passes/GlobalTypeOptimization.cpp b/src/passes/GlobalTypeOptimization.cpp index 865fe8f69..2c0799874 100644 --- a/src/passes/GlobalTypeOptimization.cpp +++ b/src/passes/GlobalTypeOptimization.cpp @@ -24,6 +24,7 @@ #include "ir/effects.h" #include "ir/localize.h" +#include "ir/ordering.h" #include "ir/struct-utils.h" #include "ir/subtypes.h" #include "ir/type-updating.h" @@ -392,12 +393,19 @@ struct GlobalTypeOptimization : public Pass { // Map to the new index. curr->index = newIndex; } else { - // This field was removed, so just emit drops of our children (plus a - // trap if the input is null). + // This field was removed, so just emit drops of our children, plus a + // trap if the ref is null. Note that we must preserve the order of + // operations here: the trap on a null ref happens after the value, + // which might have side effects. Builder builder(*getModule()); - replaceCurrent(builder.makeSequence( - builder.makeDrop(builder.makeRefAs(RefAsNonNull, curr->ref)), - builder.makeDrop(curr->value))); + auto flipped = getResultOfFirst(curr->ref, + builder.makeDrop(curr->value), + getFunction(), + getModule(), + getPassOptions()); + replaceCurrent( + builder.makeDrop(builder.makeRefAs(RefAsNonNull, flipped))); + addedLocals = true; } } |