Skip to content

Commit 04e8596

Browse files
authored
Fix folding for *.load_splat and table.fill (#1486)
Also remove default case from `ir-util.cc` so we get compile warnings in the future.
1 parent bd52b88 commit 04e8596

File tree

3 files changed

+879
-12
lines changed

3 files changed

+879
-12
lines changed

src/ir-util.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ ModuleContext::Arities ModuleContext::GetExprArity(const Expr& expr) const {
171171
case ExprType::MemoryFill:
172172
case ExprType::MemoryCopy:
173173
case ExprType::TableCopy:
174+
case ExprType::TableFill:
174175
return { 3, 0 };
175176

176177
case ExprType::AtomicLoad:
@@ -181,6 +182,7 @@ ModuleContext::Arities ModuleContext::GetExprArity(const Expr& expr) const {
181182
case ExprType::Unary:
182183
case ExprType::TableGet:
183184
case ExprType::RefIsNull:
185+
case ExprType::LoadSplat:
184186
return { 1, 1 };
185187

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

258260
case ExprType::SimdShuffleOp:
259261
return { 2, 1 };
260-
261-
default:
262-
fprintf(stderr, "bad expr type: %s\n", GetExprTypeName(expr));
263-
assert(0);
264-
return { 0, 0 };
265262
}
266263
}

test/roundtrip/fold-reference-types.txt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,47 @@
33

44
(module
55
(table $t 1 externref)
6+
(elem declare func 0)
67
(func
7-
i32.const 0
8-
i32.const 0
9-
table.get $t
10-
table.set $t
8+
(local externref)
9+
10+
i32.const 0 table.get $t drop
11+
i32.const 0 local.get 0 table.set $t
12+
local.get 0 i32.const 0 table.grow $t drop
13+
table.size $t drop
14+
i32.const 0 local.get 0 i32.const 0 table.fill $t
15+
ref.null extern drop
16+
local.get 0 ref.is_null drop
17+
ref.func 0 drop
1118
)
1219
)
1320
(;; STDOUT ;;;
1421
(module
1522
(type (;0;) (func))
1623
(func (;0;) (type 0)
24+
(local externref)
25+
(drop
26+
(table.get 0
27+
(i32.const 0)))
1728
(table.set 0
1829
(i32.const 0)
19-
(table.get 0
20-
(i32.const 0))))
21-
(table (;0;) 1 externref))
30+
(local.get 0))
31+
(drop
32+
(table.grow 0
33+
(local.get 0)
34+
(i32.const 0)))
35+
(drop
36+
(table.size 0))
37+
(table.fill 0
38+
(i32.const 0)
39+
(local.get 0)
40+
(i32.const 0))
41+
(drop
42+
(ref.null extern))
43+
(drop
44+
(ref.is_null (local.get 0)))
45+
(drop
46+
(ref.func 0)))
47+
(table (;0;) 1 externref)
48+
(elem (;0;) declare func 0))
2249
;;; STDOUT ;;)

0 commit comments

Comments
 (0)