From c449f41678d5e1699d634855743f5874ae6ec6e4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 21 Nov 2022 15:54:21 -0800 Subject: Code Pushing: Ignore unreachable sets (#5284) Normally we ignore them anyhow (unreachability is an effect, either a trap or a control flow switch), but in traps-never-happen mode we can ignore a trap, so we need to check this manually. --- src/passes/CodePushing.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/passes/CodePushing.cpp') diff --git a/src/passes/CodePushing.cpp b/src/passes/CodePushing.cpp index 20f16b145..2b45dda16 100644 --- a/src/passes/CodePushing.cpp +++ b/src/passes/CodePushing.cpp @@ -323,6 +323,26 @@ private: assert(i > 0); i--; auto* pushable = isPushable(list[i]); + if (pushable && pushable->type == Type::unreachable) { + // Don't try to push something unreachable. If we did, then we'd need to + // refinalize the block we are moving it from: + // + // (block $unreachable + // (local.set $x (unreachable)) + // (if (..) + // (.. (local.get $x)) + // ) + // + // The block should not be unreachable if the local.set is moved into + // the if arm (the if arm may not execute, so the if itself will not + // change type). It is simpler to avoid this complexity and leave this + // to DCE to simplify first. + // + // (Note that the side effect of trapping will normally prevent us from + // trying to push something unreachable, but in traps-never-happen mode + // we are allowed to ignore that, and so we need this check.) + pushable = nullptr; + } if (!pushable) { // Something that is staying where it is, so anything we push later must // move past it. Note the effects and continue. -- cgit v1.2.3