From 3e336052ea820be3e2da722f4a02f68d75283a6d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 20 May 2024 11:34:23 -0700 Subject: SimplifyGlobals: Do not switch a get to use a global of another type (#6605) If we wanted to switch types in such cases we'd need to refinalize (which is likely worth doing, though other passes should refine globals anyhow). --- src/passes/SimplifyGlobals.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/passes/SimplifyGlobals.cpp') diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp index d4a6e1f3b..461fe2890 100644 --- a/src/passes/SimplifyGlobals.cpp +++ b/src/passes/SimplifyGlobals.cpp @@ -317,7 +317,14 @@ struct GlobalUseModifier : public WalkerPass> { void visitGlobalGet(GlobalGet* curr) { auto iter = copiedParentMap->find(curr->name); if (iter != copiedParentMap->end()) { - curr->name = iter->second; + auto original = iter->second; + // Only apply this optimization if the global we are switching to has the + // right type for us. + // TODO: We could also allow it to be more refined, but would then need to + // refinalize. + if (getModule()->getGlobal(original)->type == curr->type) { + curr->name = original; + } } } -- cgit v1.2.3