From 6d2364b55e4c81b0b2f7d15778619c40d1ded4d3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Sep 2023 15:51:14 -0700 Subject: TupleOptimization: Handle copies of different types in unreachable code (#5956) --- src/passes/TupleOptimization.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/passes/TupleOptimization.cpp') diff --git a/src/passes/TupleOptimization.cpp b/src/passes/TupleOptimization.cpp index f4fd0910b..e4fb1cf00 100644 --- a/src/passes/TupleOptimization.cpp +++ b/src/passes/TupleOptimization.cpp @@ -125,10 +125,18 @@ struct TupleOptimization : public WalkerPass> { // a get), or a tuple.make. if (auto* tee = value->dynCast()) { assert(tee->isTee()); - validUses[tee->index]++; - validUses[curr->index]++; - copiedIndexes[tee->index].insert(curr->index); - copiedIndexes[curr->index].insert(tee->index); + // We don't want to count anything as valid if the inner tee is + // unreachable. In that case the outer tee is also unreachable, of + // course, and in fact they might not even have the same tuple type or + // the inner one might not even be a tuple (since we are in unreachable + // code, that is possible). We could try to optimize unreachable tees in + // some cases, but it's simpler to let DCE simplify the code first. + if (tee->type != Type::unreachable) { + validUses[tee->index]++; + validUses[curr->index]++; + copiedIndexes[tee->index].insert(curr->index); + copiedIndexes[curr->index].insert(tee->index); + } } else if (auto* get = value->dynCast()) { validUses[get->index]++; validUses[curr->index]++; -- cgit v1.2.3