From 4e24fdfd74347dc40ba32efee6b154e6ec9827c0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 16 Sep 2022 14:11:25 -0700 Subject: Effects: Clarify trap effect meaning, and consider infinite loops to trap due to timeout (#5039) I think this simplifies the logic behind what we consider to trap. Before we had kind of a hack in visitLoop that now has a more clear reasoning behind it: we consider as trapping things that trap in all VMs all the time, or will eventually. So a single allocation doesn't trap, but an unbounded amount can, and an infinite loop is considered to trap as well (a timeout in a VM will be hit eventually, somehow). This means we cannot optimize way a trivial infinite loop with no effects in it, while (1) {} But we can optimize it out in trapsNeverHappen mode. In any event, such a loop is not a realistic situation; an infinite loop with some other effect in it, like a call to an import, will not be optimized out, of course. Also clarify some other things regarding traps and trapsNeverHappen following recent discussions in https://github.com/emscripten-core/emscripten/issues/17732 Specifically, TNH will never be allowed to remove calls to imports. --- test/passes/remove-unused-names_remove-unused-brs_vacuum.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/passes/remove-unused-names_remove-unused-brs_vacuum.txt') diff --git a/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt b/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt index 83be83c5a..ca856396e 100644 --- a/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt +++ b/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt @@ -71,8 +71,12 @@ (block $label$3 (block (if - (i32.eqz - (local.get $var$8) + (local.get $var$8) + (loop $label$8 + (if + (local.get $var$3) + (br $label$8) + ) ) (if (i32.eqz -- cgit v1.2.3