diff options
author | Thomas Lively <tlively123@gmail.com> | 2024-12-02 15:18:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-02 23:18:57 +0000 |
commit | 74782d217ed15dd73b58b1636c563aa51334a576 (patch) | |
tree | 4a4de972ae57b23ff6e0b02fbccb853a45cde881 /src/passes/RemoveUnusedBrs.cpp | |
parent | 31c988b30556ef000bd2212754d7fc5beebf08d2 (diff) | |
download | binaryen-74782d217ed15dd73b58b1636c563aa51334a576.tar.gz binaryen-74782d217ed15dd73b58b1636c563aa51334a576.tar.bz2 binaryen-74782d217ed15dd73b58b1636c563aa51334a576.zip |
Do not sink blocks into ifs with unreachable conditions (#7129)
RemoveUnusedBrs sinks blocks into If arms when those arms contain
branches to the blocks and the other arm and condition do not. Now that
we type Ifs with unreachable conditions as unreachable, it is possible
for the If arms to have a different type than the block that would be
sunk, so sinking the block would produce invalid IR. Fix the problem by
never sinking blocks into Ifs with unreachable conditions.
Fixes #7128.
Diffstat (limited to 'src/passes/RemoveUnusedBrs.cpp')
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 44549f68d..32f7bd48a 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -757,6 +757,12 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { replaceCurrent(loop); worked = true; } else if (auto* iff = curr->list[0]->dynCast<If>()) { + if (iff->condition->type == Type::unreachable) { + // The block result type may not be compatible with the arm result + // types since the unreachable If can satisfy any type of block. + // Just leave this for DCE. + return; + } // The label can't be used in the condition. if (BranchUtils::BranchSeeker::count(iff->condition, curr->name) == 0) { |