diff options
author | Alon Zakai <azakai@google.com> | 2024-05-20 11:34:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-20 11:34:23 -0700 |
commit | 3e336052ea820be3e2da722f4a02f68d75283a6d (patch) | |
tree | c2d59aa758d01c7a27abdc72e860f924bb851a48 /src/passes/SimplifyGlobals.cpp | |
parent | 5d64afabbd0da07506f68d6f22b3b358f0ca12b6 (diff) | |
download | binaryen-3e336052ea820be3e2da722f4a02f68d75283a6d.tar.gz binaryen-3e336052ea820be3e2da722f4a02f68d75283a6d.tar.bz2 binaryen-3e336052ea820be3e2da722f4a02f68d75283a6d.zip |
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).
Diffstat (limited to 'src/passes/SimplifyGlobals.cpp')
-rw-r--r-- | src/passes/SimplifyGlobals.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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<PostWalker<GlobalUseModifier>> { 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; + } } } |