Skip to content

Commit 616abe4

Browse files
authored
Use splatted zero vector in makeZero (#2164)
This prevents the optimizer from producing v128.const instructions, which are not supported by V8 at this time.
1 parent 917fabf commit 616abe4

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/ir/literal-utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef wasm_ir_literal_utils_h
1818
#define wasm_ir_literal_utils_h
1919

20+
#include "wasm-builder.h"
2021
#include "wasm.h"
2122

2223
namespace wasm {
@@ -31,6 +32,13 @@ inline Expression* makeFromInt32(int32_t x, Type type, Module& wasm) {
3132
}
3233

3334
inline Expression* makeZero(Type type, Module& wasm) {
35+
// TODO: Switch to using v128.const once V8 supports it
36+
// (https://bugs.chromium.org/p/v8/issues/detail?id=8460)
37+
if (type == v128) {
38+
Builder builder(wasm);
39+
return builder.makeUnary(SplatVecI32x4,
40+
builder.makeConst(Literal(int32_t(0))));
41+
}
3442
return makeFromInt32(0, type, wasm);
3543
}
3644

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(module
22
(type $FUNCSIG$vi (func (param i32)))
33
(type $FUNCSIG$vii (func (param i32 i32)))
4+
(type $FUNCSIG$v (func))
5+
(memory $0 1 1)
46
(global $global$0 (mut i32) (i32.const 1))
57
(func $basics (; 0 ;) (type $FUNCSIG$vi) (param $x i32)
68
(local $y i32)
@@ -199,4 +201,14 @@
199201
(local.get $x)
200202
)
201203
)
204+
(func $simd-zero (; 4 ;) (type $FUNCSIG$v)
205+
(local $0 v128)
206+
(v128.store align=4
207+
(i32.const 0)
208+
(i32x4.splat
209+
(i32.const 0)
210+
)
211+
)
212+
(unreachable)
213+
)
202214
)
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(module
2+
(memory 1 1)
23
(global $global$0 (mut i32) (i32.const 1))
34
(func $basics (param $x i32)
45
(local $y i32)
@@ -98,5 +99,12 @@
9899
)
99100
(call $nomerge (local.get $x) (local.get $x))
100101
)
102+
(func $simd-zero
103+
(local $0 v128)
104+
(v128.store align=4
105+
(i32.const 0)
106+
(local.get $0)
107+
)
108+
(unreachable)
109+
)
101110
)
102-

0 commit comments

Comments
 (0)