File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,14 @@ struct GlobalUseModifier : public WalkerPass<PostWalker<GlobalUseModifier>> {
317317 void visitGlobalGet (GlobalGet* curr) {
318318 auto iter = copiedParentMap->find (curr->name );
319319 if (iter != copiedParentMap->end ()) {
320- curr->name = iter->second ;
320+ auto original = iter->second ;
321+ // Only apply this optimization if the global we are switching to has the
322+ // right type for us.
323+ // TODO: We could also allow it to be more refined, but would then need to
324+ // refinalize.
325+ if (getModule ()->getGlobal (original)->type == curr->type ) {
326+ curr->name = original;
327+ }
321328 }
322329 }
323330
Original file line number Diff line number Diff line change 3131 )
3232)
3333
34+ (module
35+ ;; CHECK: (type $struct (struct ))
36+ (type $struct (struct ))
37+
38+ ;; CHECK: (type $1 (func (result anyref)))
39+
40+ ;; CHECK: (global $a (ref $struct) (struct.new_default $struct))
41+ (global $a (ref $struct ) (struct.new_default $struct ))
42+ ;; CHECK: (global $b (ref $struct) (global.get $a))
43+ (global $b (ref $struct ) (global.get $a ))
44+ ;; CHECK: (global $c (ref null $struct) (global.get $a))
45+ (global $c (ref null $struct ) (global.get $a ))
46+
47+ ;; CHECK: (func $get-c (type $1) (result anyref)
48+ ;; CHECK-NEXT: (global.get $c)
49+ ;; CHECK-NEXT: )
50+ (func $get-c (result anyref )
51+ ;; $c has a less-refined type than the other two. We do not switch this to
52+ ;; get from either $a or $b because of that, but we could if we also
53+ ;; refinalized TODO
54+ (global.get $c )
55+ )
56+ )
57+
You can’t perform that action at this time.
0 commit comments