Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 22 additions & 20 deletions src/passes/I64ToI32Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,33 +300,35 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
void visitRefFunc(RefFunc* curr) {
auto sig = curr->type.getHeapType().getSignature();

auto lowerTypes = [](Type types) {
bool hasI64 = false;
for (auto t : types) {
if (t == Type::i64) {
hasI64 = true;
break;
}
}
if (!hasI64) {
return types;
bool hasI64Param = false;
for (auto t : sig.params) {
if (t == Type::i64) {
hasI64Param = true;
break;
}
std::vector<Type> newTypes;
for (auto t : types) {
}
auto params = sig.params;
if (hasI64Param) {
std::vector<Type> newParams;
for (auto t : sig.params) {
if (t == Type::i64) {
newTypes.push_back(Type::i32);
newTypes.push_back(Type::i32);
newParams.push_back(Type::i32);
newParams.push_back(Type::i32);
} else {
newTypes.push_back(t);
newParams.push_back(t);
}
}
return Type(newTypes);
params = Type(newParams);
};
auto results = sig.results;
// Update the results the same way we do when visiting functions. We use a
// global rather than multivalue to lower i64 results.
if (results == Type::i64) {
results = Type::i32;
}

auto newParams = lowerTypes(sig.params);
auto newResults = lowerTypes(sig.results);
if (newParams != sig.params || newResults != sig.results) {
curr->type = curr->type.with(HeapType(Signature(newParams, newResults)));
if (params != sig.params || results != sig.results) {
curr->type = curr->type.with(HeapType(Signature(params, results)));
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/lit/passes/flatten_i64-to-i32-lowering.wast
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,26 @@
)
)
)

;; Make sure we update the ref.func in the table with the correct return type.
(module
(table 1 1 funcref)

(elem (i32.const 0) $f)

;; CHECK: (type $0 (func (result i32)))

;; CHECK: (global $i64toi32_i32$HIGH_BITS (mut i32) (i32.const 0))

;; CHECK: (table $0 1 1 funcref)

;; CHECK: (elem $0 (i32.const 0) $f)

;; CHECK: (func $f (type $0) (result i32)
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
(func $f (result i64)
(unreachable)
)
)
Loading