Skip to content

Commit

Permalink
Fix folding for *.load_splat and table.fill (#1486)
Browse files Browse the repository at this point in the history
Also remove default case from `ir-util.cc` so we get compile warnings in
the future.
  • Loading branch information
binji authored Jul 16, 2020
1 parent bd52b88 commit 04e8596
Show file tree
Hide file tree
Showing 3 changed files with 879 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/ir-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ ModuleContext::Arities ModuleContext::GetExprArity(const Expr& expr) const {
case ExprType::MemoryFill:
case ExprType::MemoryCopy:
case ExprType::TableCopy:
case ExprType::TableFill:
return { 3, 0 };

case ExprType::AtomicLoad:
Expand All @@ -181,6 +182,7 @@ ModuleContext::Arities ModuleContext::GetExprArity(const Expr& expr) const {
case ExprType::Unary:
case ExprType::TableGet:
case ExprType::RefIsNull:
case ExprType::LoadSplat:
return { 1, 1 };

case ExprType::Drop:
Expand Down Expand Up @@ -257,10 +259,5 @@ ModuleContext::Arities ModuleContext::GetExprArity(const Expr& expr) const {

case ExprType::SimdShuffleOp:
return { 2, 1 };

default:
fprintf(stderr, "bad expr type: %s\n", GetExprTypeName(expr));
assert(0);
return { 0, 0 };
}
}
41 changes: 34 additions & 7 deletions test/roundtrip/fold-reference-types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,47 @@

(module
(table $t 1 externref)
(elem declare func 0)
(func
i32.const 0
i32.const 0
table.get $t
table.set $t
(local externref)

i32.const 0 table.get $t drop
i32.const 0 local.get 0 table.set $t
local.get 0 i32.const 0 table.grow $t drop
table.size $t drop
i32.const 0 local.get 0 i32.const 0 table.fill $t
ref.null extern drop
local.get 0 ref.is_null drop
ref.func 0 drop
)
)
(;; STDOUT ;;;
(module
(type (;0;) (func))
(func (;0;) (type 0)
(local externref)
(drop
(table.get 0
(i32.const 0)))
(table.set 0
(i32.const 0)
(table.get 0
(i32.const 0))))
(table (;0;) 1 externref))
(local.get 0))
(drop
(table.grow 0
(local.get 0)
(i32.const 0)))
(drop
(table.size 0))
(table.fill 0
(i32.const 0)
(local.get 0)
(i32.const 0))
(drop
(ref.null extern))
(drop
(ref.is_null (local.get 0)))
(drop
(ref.func 0)))
(table (;0;) 1 externref)
(elem (;0;) declare func 0))
;;; STDOUT ;;)
Loading

0 comments on commit 04e8596

Please sign in to comment.