Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TupleOptimization: Properly handle subtyping in copies #6786

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/passes/TupleOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,13 @@ struct TupleOptimization : public WalkerPass<PostWalker<TupleOptimization>> {
// we were confused earlier and the target should not be.
assert(sourceBase);

// The source and target may have different lane types due to subtyping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we use "element" rather than "lane" to describe tuple elements. ("lane" is specific to SIMD vectors.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed. Also fixed some existing appearances.

// (but their sizes must be equal).
auto sourceType = value->type;
assert(sourceType.size() == type.size());

for (Index i = 0; i < type.size(); i++) {
auto* get = builder.makeLocalGet(sourceBase + i, type[i]);
auto* get = builder.makeLocalGet(sourceBase + i, sourceType[i]);
contents.push_back(builder.makeLocalSet(targetBase + i, get));
}
replace(builder.makeBlock(contents));
Expand Down
38 changes: 38 additions & 0 deletions test/lit/passes/tuple-optimization.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1026,4 +1026,42 @@
)
)
)

;; CHECK: (func $tuple.lane.subtyping (type $0)
;; CHECK-NEXT: (local $tuple_null (tuple i32 nullref))
;; CHECK-NEXT: (local $tuple_eq (tuple i32 eqref))
;; CHECK-NEXT: (local $2 i32)
;; CHECK-NEXT: (local $3 nullref)
;; CHECK-NEXT: (local $4 i32)
;; CHECK-NEXT: (local $5 eqref)
;; CHECK-NEXT: (block
;; CHECK-NEXT: (local.set $2
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $3
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $4
;; CHECK-NEXT: (local.get $2)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $5
;; CHECK-NEXT: (local.get $3)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $tuple.lane.subtyping
(local $tuple_null (tuple i32 nullref))
(local $tuple_eq (tuple i32 eqref))
;; The tee emits a nullref in the second lane, which is written to a lane of
;; eqref. That is, the source and the target do not have identical type,
;; which we need to properly handle and not error.
(local.set $tuple_eq
(local.tee $tuple_null
(tuple.make 2
(i32.const 0)
(ref.null none)
)
)
)
)
)
Loading