From 74782d217ed15dd73b58b1636c563aa51334a576 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Mon, 2 Dec 2024 15:18:57 -0800 Subject: 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. --- src/passes/RemoveUnusedBrs.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') 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> { replaceCurrent(loop); worked = true; } else if (auto* iff = curr->list[0]->dynCast()) { + 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) { -- cgit v1.2.3