summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-08-17 14:26:24 -0700
committerGitHub <noreply@github.com>2021-08-17 21:26:24 +0000
commitb82be0fe1abd3c56cc85150c76efbd66db6fe32e (patch)
tree886cf25d9cfd2bd38c18cbdcf60b0c7386a1f50d /src
parentd1bea49163be364d6f8b277b35510555211374b5 (diff)
downloadbinaryen-b82be0fe1abd3c56cc85150c76efbd66db6fe32e.tar.gz
binaryen-b82be0fe1abd3c56cc85150c76efbd66db6fe32e.tar.bz2
binaryen-b82be0fe1abd3c56cc85150c76efbd66db6fe32e.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/passes/LocalCSE.cpp9
1 files changed, 9 insertions, 0 deletions
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.