Skip to content

Commit 0f41b07

Browse files
authored
Do not precompute v128 expressions (#1839)
Without this change, sequences like `i32.const 0, i32x4.splat` will get precomputed to v128.const ops, which are much larger and also not implemented in V8 yet. Until we have SIMD-aware optimization passes or at least engine support for v128.const, do not perform such transformations.
1 parent fcbcf3b commit 0f41b07

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/passes/Precompute.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ struct Precompute : public WalkerPass<PostWalker<Precompute, UnifiedExpressionVi
161161
void visitExpression(Expression* curr) {
162162
// TODO: if get_local, only replace with a constant if we don't care about size...?
163163
if (curr->is<Const>() || curr->is<Nop>()) return;
164+
// Until engines implement v128.const and we have SIMD-aware optimizations
165+
// that can break large v128.const instructions into smaller consts and
166+
// splats, do not try to precompute v128 expressions.
167+
if (curr->type == v128) return;
164168
// try to evaluate this into a const
165169
Flow flow = precomputeExpression(curr);
166170
if (flow.breaking()) {

test/passes/precompute.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(type $1 (func (result i32)))
44
(type $2 (func))
55
(type $3 (func (result f64)))
6+
(type $4 (func (result v128)))
67
(memory $0 0)
78
(global $global i32 (i32.const 1))
89
(global $global-mut (mut i32) (i32.const 2))
@@ -211,4 +212,9 @@
211212
(i32.const 2)
212213
)
213214
)
215+
(func $no-simd-precompute (; 11 ;) (type $4) (result v128)
216+
(i32x4.splat
217+
(i32.const 0)
218+
)
219+
)
214220
)

test/passes/precompute.wast

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,9 @@
306306
)
307307
)
308308
)
309+
(func $no-simd-precompute (result v128)
310+
(i32x4.splat
311+
(i32.const 0)
312+
)
313+
)
309314
)

0 commit comments

Comments
 (0)