From b82be0fe1abd3c56cc85150c76efbd66db6fe32e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 17 Aug 2021 14:26:24 -0700 Subject: LocalCSE: ignore traps (#4085) If we replace A A A with (local.set A) (local.get) (local.get) then it is ok for A to trap (so long as it does so deterministically), as if it does trap then the first appearance will do so, and the others not be reached anyhow. This helps GC code as often there are repeated struct.gets and such that may trap. --- src/passes/LocalCSE.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/passes/LocalCSE.cpp b/src/passes/LocalCSE.cpp index b55da976c..1ae77d155 100644 --- a/src/passes/LocalCSE.cpp +++ b/src/passes/LocalCSE.cpp @@ -422,6 +422,15 @@ struct Checker // away repeated apperances if it has any. EffectAnalyzer effects(options, getModule()->features, curr); + // We can ignore traps here, as we replace a repeating expression with a + // single appearance of it, a store to a local, and gets in the other + // locations, and so if the expression traps then the first appearance - + // that we keep around - would trap, and the others are never reached + // anyhow. (The other checks we perform here, including invalidation and + // determinism, will ensure that either all of the appearances trap, or + // none of them.) + effects.trap = false; + // We also cannot optimize away something that is intrinsically // nondeterministic: even if it has no side effects, if it may return a // different result each time, then we cannot optimize away repeats. -- cgit v1.2.3