2020-05-06 20:48:04 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/wasm/compilation-environment.h"
|
|
|
|
#include "src/wasm/wasm-tier.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/wasm/wasm-run-utils.h"
|
|
|
|
#include "test/common/wasm/flag-utils.h"
|
2020-09-03 17:28:44 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
2020-05-06 20:48:04 +00:00
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
namespace test_run_wasm_simd {
|
|
|
|
|
2020-08-04 11:09:23 +00:00
|
|
|
#define WASM_SIMD_TEST(name) \
|
|
|
|
void RunWasm_##name##_Impl(LowerSimd lower_simd, \
|
|
|
|
TestExecutionTier execution_tier); \
|
|
|
|
TEST(RunWasm_##name##_simd_lowered) { \
|
|
|
|
EXPERIMENTAL_FLAG_SCOPE(simd); \
|
|
|
|
RunWasm_##name##_Impl(kLowerSimd, TestExecutionTier::kTurbofan); \
|
|
|
|
} \
|
|
|
|
void RunWasm_##name##_Impl(LowerSimd lower_simd, \
|
|
|
|
TestExecutionTier execution_tier)
|
2020-05-06 20:48:04 +00:00
|
|
|
|
|
|
|
WASM_SIMD_TEST(I8x16ToF32x4) {
|
|
|
|
WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
|
|
|
|
float* g = r.builder().AddGlobal<float>(kWasmS128);
|
|
|
|
byte param1 = 0;
|
|
|
|
BUILD(r,
|
2020-12-17 16:56:08 +00:00
|
|
|
WASM_GLOBAL_SET(
|
2020-05-06 20:48:04 +00:00
|
|
|
0, WASM_SIMD_UNOP(kExprF32x4Sqrt,
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_I8x16_SPLAT(WASM_LOCAL_GET(param1)))),
|
2020-05-06 20:48:04 +00:00
|
|
|
WASM_ONE);
|
|
|
|
|
|
|
|
// Arbitrary pattern that doesn't end up creating a NaN.
|
|
|
|
r.Call(0x5b);
|
|
|
|
float f = bit_cast<float>(0x5b5b5b5b);
|
|
|
|
float actual = ReadLittleEndianValue<float>(&g[0]);
|
|
|
|
float expected = std::sqrt(f);
|
|
|
|
CHECK_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2020-09-22 23:58:40 +00:00
|
|
|
WASM_SIMD_TEST(F64x2_Call_Return) {
|
|
|
|
// Check that calling a function with i16x8 arguments, and returns i16x8, is
|
|
|
|
// correctly lowered. The signature of the functions are always lowered to 4
|
|
|
|
// Word32, so each i16x8 needs to be correctly converted.
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmRunner<double, double, double> r(execution_tier, lower_simd);
|
|
|
|
|
|
|
|
WasmFunctionCompiler& fn = r.NewFunction(sigs.s_ss());
|
|
|
|
BUILD(fn,
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_BINOP(kExprF64x2Min, WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)));
|
2020-09-22 23:58:40 +00:00
|
|
|
|
|
|
|
byte c1[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
|
|
byte c2[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0x7f,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0x7f};
|
|
|
|
|
|
|
|
BUILD(r,
|
|
|
|
WASM_SIMD_F64x2_EXTRACT_LANE(
|
|
|
|
0, WASM_CALL_FUNCTION(fn.function_index(), WASM_SIMD_CONSTANT(c1),
|
|
|
|
WASM_SIMD_CONSTANT(c2))));
|
|
|
|
CHECK_EQ(0, r.Call(double{0}, bit_cast<double>(0x7fefffffffffffff)));
|
|
|
|
}
|
|
|
|
|
2020-09-10 20:56:27 +00:00
|
|
|
WASM_SIMD_TEST(F32x4_Call_Return) {
|
2020-09-03 17:28:44 +00:00
|
|
|
// Check that functions that return F32x4 are correctly lowered into 4 int32
|
|
|
|
// nodes. The signature of such functions are always lowered to 4 Word32, and
|
|
|
|
// if the last operation before the return was a f32x4, it will need to be
|
|
|
|
// bitcasted from float to int.
|
|
|
|
TestSignatures sigs;
|
2020-09-10 20:56:27 +00:00
|
|
|
WasmRunner<float, float> r(execution_tier, lower_simd);
|
2020-09-03 17:28:44 +00:00
|
|
|
|
|
|
|
// A simple function that just calls f32x4.neg on the param.
|
|
|
|
WasmFunctionCompiler& fn = r.NewFunction(sigs.s_s());
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(fn, WASM_SIMD_UNOP(kExprF32x4Neg, WASM_LOCAL_GET(0)));
|
2020-09-03 17:28:44 +00:00
|
|
|
|
|
|
|
// TODO(v8:10507)
|
|
|
|
// Use i32x4 splat since scalar lowering has a problem with f32x4 as a param
|
|
|
|
// to a function call, the lowering is not correct yet.
|
|
|
|
BUILD(r,
|
2020-09-10 20:56:27 +00:00
|
|
|
WASM_SIMD_F32x4_EXTRACT_LANE(
|
|
|
|
0, WASM_CALL_FUNCTION(fn.function_index(),
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_F32x4_SPLAT(WASM_LOCAL_GET(0)))));
|
2020-09-10 20:56:27 +00:00
|
|
|
CHECK_EQ(-1.0, r.Call(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
WASM_SIMD_TEST(I8x16_Call_Return) {
|
|
|
|
// Check that calling a function with i8x16 arguments, and returns i8x16, is
|
|
|
|
// correctly lowered. The signature of the functions are always lowered to 4
|
|
|
|
// Word32, so each i8x16 needs to be correctly converted.
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmRunner<uint32_t, uint32_t> r(execution_tier, lower_simd);
|
|
|
|
|
|
|
|
WasmFunctionCompiler& fn = r.NewFunction(sigs.s_ss());
|
|
|
|
BUILD(fn,
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_BINOP(kExprI8x16Add, WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)));
|
2020-09-10 20:56:27 +00:00
|
|
|
|
|
|
|
BUILD(r,
|
|
|
|
WASM_SIMD_I8x16_EXTRACT_LANE(
|
|
|
|
0, WASM_CALL_FUNCTION(fn.function_index(),
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_I8x16_SPLAT(WASM_LOCAL_GET(0)),
|
|
|
|
WASM_SIMD_I8x16_SPLAT(WASM_LOCAL_GET(0)))));
|
2020-09-10 20:56:27 +00:00
|
|
|
CHECK_EQ(2, r.Call(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
WASM_SIMD_TEST(I16x8_Call_Return) {
|
|
|
|
// Check that calling a function with i16x8 arguments, and returns i16x8, is
|
|
|
|
// correctly lowered. The signature of the functions are always lowered to 4
|
|
|
|
// Word32, so each i16x8 needs to be correctly converted.
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmRunner<uint32_t, uint32_t> r(execution_tier, lower_simd);
|
|
|
|
|
|
|
|
WasmFunctionCompiler& fn = r.NewFunction(sigs.s_ss());
|
|
|
|
BUILD(fn,
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_BINOP(kExprI16x8Add, WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)));
|
2020-09-10 20:56:27 +00:00
|
|
|
|
|
|
|
BUILD(r,
|
|
|
|
WASM_SIMD_I16x8_EXTRACT_LANE(
|
2020-09-03 17:28:44 +00:00
|
|
|
0, WASM_CALL_FUNCTION(fn.function_index(),
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_I16x8_SPLAT(WASM_LOCAL_GET(0)),
|
|
|
|
WASM_SIMD_I16x8_SPLAT(WASM_LOCAL_GET(0)))));
|
2020-09-10 20:56:27 +00:00
|
|
|
CHECK_EQ(2, r.Call(1));
|
2020-09-03 17:28:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 17:10:41 +00:00
|
|
|
WASM_SIMD_TEST(I64x2_Call_Return) {
|
|
|
|
// Check that calling a function with i64x2 arguments, and returns i64x2, is
|
|
|
|
// correctly lowered. The signature of the functions are always lowered to 4
|
|
|
|
// Word32, so each i64x2 needs to be correctly converted.
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmRunner<uint64_t, uint64_t> r(execution_tier, lower_simd);
|
|
|
|
|
|
|
|
WasmFunctionCompiler& fn = r.NewFunction(sigs.s_ss());
|
|
|
|
BUILD(fn,
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_BINOP(kExprI64x2Add, WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)));
|
2020-09-15 17:10:41 +00:00
|
|
|
|
|
|
|
BUILD(r,
|
|
|
|
WASM_SIMD_I64x2_EXTRACT_LANE(
|
|
|
|
0, WASM_CALL_FUNCTION(fn.function_index(),
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_I64x2_SPLAT(WASM_LOCAL_GET(0)),
|
|
|
|
WASM_SIMD_I64x2_SPLAT(WASM_LOCAL_GET(0)))));
|
2020-09-15 17:10:41 +00:00
|
|
|
CHECK_EQ(2, r.Call(1));
|
|
|
|
}
|
|
|
|
|
2020-09-03 21:38:39 +00:00
|
|
|
WASM_SIMD_TEST(I8x16Eq_ToTest_S128Const) {
|
|
|
|
// Test implementation of S128Const in scalar lowering, this test case was
|
|
|
|
// causing a crash.
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmRunner<uint32_t> r(execution_tier, lower_simd);
|
|
|
|
|
|
|
|
byte c1[16] = {0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40};
|
|
|
|
byte c2[16] = {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02};
|
|
|
|
byte c3[16] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
|
|
|
|
|
|
BUILD(r,
|
|
|
|
WASM_SIMD_BINOP(kExprI8x16Eq, WASM_SIMD_CONSTANT(c1),
|
|
|
|
WASM_SIMD_CONSTANT(c2)),
|
|
|
|
WASM_SIMD_CONSTANT(c3), WASM_SIMD_OP(kExprI8x16Eq),
|
|
|
|
WASM_SIMD_OP(kExprI8x16ExtractLaneS), TO_BYTE(4));
|
|
|
|
CHECK_EQ(0xffffffff, r.Call());
|
|
|
|
}
|
|
|
|
|
2020-09-11 03:35:36 +00:00
|
|
|
WASM_SIMD_TEST(F32x4_S128Const) {
|
|
|
|
// Test that S128Const lowering is done correctly when it is used as an input
|
|
|
|
// into a f32x4 operation. This was triggering a CHECK failure in the
|
|
|
|
// register-allocator-verifier.
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmRunner<float> r(execution_tier, lower_simd);
|
|
|
|
|
|
|
|
// f32x4(1.0, 2.0, 3.0, 4.0)
|
|
|
|
byte c1[16] = {0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40,
|
|
|
|
0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x80, 0x40};
|
|
|
|
// f32x4(5.0, 6.0, 7.0, 8.0)
|
|
|
|
byte c2[16] = {0x00, 0x00, 0xa0, 0x40, 0x00, 0x00, 0xc0, 0x40,
|
|
|
|
0x00, 0x00, 0xe0, 0x40, 0x00, 0x00, 0x00, 0x41};
|
|
|
|
|
|
|
|
BUILD(r,
|
|
|
|
WASM_SIMD_BINOP(kExprF32x4Min, WASM_SIMD_CONSTANT(c1),
|
|
|
|
WASM_SIMD_CONSTANT(c2)),
|
|
|
|
WASM_SIMD_OP(kExprF32x4ExtractLane), TO_BYTE(0));
|
|
|
|
CHECK_EQ(1.0, r.Call());
|
|
|
|
}
|
|
|
|
|
2020-09-11 23:55:59 +00:00
|
|
|
WASM_SIMD_TEST(AllTrue_DifferentShapes) {
|
|
|
|
// Test all_true lowring with splats of different shapes.
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_SIMD_I32x4_SPLAT(WASM_LOCAL_GET(0)),
|
2020-09-11 23:55:59 +00:00
|
|
|
WASM_SIMD_OP(kExprV8x16AllTrue));
|
|
|
|
|
|
|
|
CHECK_EQ(0, r.Call(0x00FF00FF));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_SIMD_I32x4_SPLAT(WASM_LOCAL_GET(0)),
|
2020-09-11 23:55:59 +00:00
|
|
|
WASM_SIMD_OP(kExprV16x8AllTrue));
|
|
|
|
|
|
|
|
CHECK_EQ(0, r.Call(0x000000FF));
|
|
|
|
}
|
2020-09-24 21:10:59 +00:00
|
|
|
|
|
|
|
// Check float input to all_true.
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, float> r(execution_tier, lower_simd);
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_SIMD_F32x4_SPLAT(WASM_LOCAL_GET(0)),
|
2020-09-24 21:10:59 +00:00
|
|
|
WASM_SIMD_OP(kExprV16x8AllTrue));
|
|
|
|
|
|
|
|
CHECK_EQ(1, r.Call(0x000F000F));
|
|
|
|
}
|
2020-09-11 23:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WASM_SIMD_TEST(AnyTrue_DifferentShapes) {
|
|
|
|
// Test any_true lowring with splats of different shapes.
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_SIMD_I32x4_SPLAT(WASM_LOCAL_GET(0)),
|
2020-09-11 23:55:59 +00:00
|
|
|
WASM_SIMD_OP(kExprV8x16AnyTrue));
|
|
|
|
|
|
|
|
CHECK_EQ(0, r.Call(0x00000000));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_SIMD_I32x4_SPLAT(WASM_LOCAL_GET(0)),
|
2020-09-11 23:55:59 +00:00
|
|
|
WASM_SIMD_OP(kExprV16x8AnyTrue));
|
|
|
|
|
|
|
|
CHECK_EQ(1, r.Call(0x000000FF));
|
|
|
|
}
|
2020-09-24 21:10:59 +00:00
|
|
|
|
|
|
|
// Check float input to any_true.
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, float> r(execution_tier, lower_simd);
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_SIMD_F32x4_SPLAT(WASM_LOCAL_GET(0)),
|
2020-09-24 21:10:59 +00:00
|
|
|
WASM_SIMD_OP(kExprV8x16AnyTrue));
|
|
|
|
|
|
|
|
CHECK_EQ(0, r.Call(0x00000000));
|
|
|
|
}
|
2020-09-11 23:55:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 23:34:51 +00:00
|
|
|
WASM_SIMD_TEST(V128_I64_PARAMS) {
|
|
|
|
// This test exercises interaction between simd and int64 lowering. The
|
|
|
|
// parameter indices were not correctly lowered because simd lowered a v128 in
|
|
|
|
// the function signature into 4 word32, and int64 was still treating it as 1
|
|
|
|
// parameter.
|
|
|
|
WasmRunner<uint64_t, uint64_t> r(execution_tier, lower_simd);
|
|
|
|
|
|
|
|
FunctionSig::Builder builder(r.zone(), 1, 2);
|
|
|
|
builder.AddParam(kWasmS128);
|
|
|
|
builder.AddParam(kWasmI64);
|
|
|
|
builder.AddReturn(kWasmS128);
|
|
|
|
FunctionSig* sig = builder.Build();
|
|
|
|
WasmFunctionCompiler& fn = r.NewFunction(sig);
|
|
|
|
|
|
|
|
// Build a function that has both V128 and I64 arguments.
|
|
|
|
BUILD(fn,
|
2020-12-17 16:55:33 +00:00
|
|
|
WASM_SIMD_I64x2_REPLACE_LANE(0, WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)));
|
2020-09-28 23:34:51 +00:00
|
|
|
|
|
|
|
BUILD(r, WASM_SIMD_I64x2_EXTRACT_LANE(
|
2020-12-17 16:55:33 +00:00
|
|
|
0, WASM_SIMD_I64x2_SPLAT(WASM_LOCAL_GET(0))));
|
2020-09-28 23:34:51 +00:00
|
|
|
|
|
|
|
CHECK_EQ(0, r.Call(0));
|
|
|
|
}
|
|
|
|
|
2020-09-30 17:20:49 +00:00
|
|
|
WASM_SIMD_TEST(I8x16WidenS_I16x8NarrowU) {
|
|
|
|
// Test any_true lowring with splats of different shapes.
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, int16_t> r(execution_tier, lower_simd);
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_SIMD_I16x8_SPLAT(WASM_LOCAL_GET(0)),
|
|
|
|
WASM_SIMD_I16x8_SPLAT(WASM_LOCAL_GET(0)),
|
2020-09-30 17:20:49 +00:00
|
|
|
WASM_SIMD_OP(kExprI8x16UConvertI16x8),
|
|
|
|
WASM_SIMD_OP(kExprI16x8SConvertI8x16Low),
|
|
|
|
WASM_SIMD_OP(kExprI32x4ExtractLane), TO_BYTE(0));
|
|
|
|
|
|
|
|
CHECK_EQ(bit_cast<int32_t>(0xffffffff), r.Call(0x7fff));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:45:48 +00:00
|
|
|
WASM_SIMD_TEST(S128SelectWithF32x4) {
|
|
|
|
WasmRunner<float, int32_t, float, int32_t> r(execution_tier, lower_simd);
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_LOCAL_GET(0), WASM_SIMD_OP(kExprI32x4Splat), WASM_LOCAL_GET(1),
|
|
|
|
WASM_SIMD_OP(kExprF32x4Splat), WASM_LOCAL_GET(2),
|
2020-11-13 02:45:48 +00:00
|
|
|
WASM_SIMD_OP(kExprI32x4Splat), WASM_SIMD_OP(kExprS128Select),
|
|
|
|
WASM_SIMD_OP(kExprF32x4ExtractLane), 0);
|
|
|
|
// Selection mask is all 0, so always select 2.0.
|
|
|
|
CHECK_EQ(2.0, r.Call(1, 2.0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
WASM_SIMD_TEST(S128AndNotWithF32x4) {
|
|
|
|
WasmRunner<float, int32_t, float> r(execution_tier, lower_simd);
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_LOCAL_GET(0), WASM_SIMD_OP(kExprI32x4Splat), WASM_LOCAL_GET(1),
|
2020-11-13 02:45:48 +00:00
|
|
|
WASM_SIMD_OP(kExprF32x4Splat), WASM_SIMD_OP(kExprS128AndNot),
|
|
|
|
WASM_SIMD_OP(kExprF32x4ExtractLane), 0);
|
|
|
|
// 0x00700000 & !0x40800000 = 0x00700000
|
|
|
|
CHECK_EQ(bit_cast<float>(0x700000),
|
|
|
|
r.Call(0x00700000, bit_cast<float>(0x40800000)));
|
|
|
|
}
|
|
|
|
|
[wasm-simd][scalar-lowering] Fix replacement for call nodes
all_true, any_true, bitmask, and extract_lane all replace a simd type
with single scalar, so we don't need to set nullptr for the extraneous
lane, and can set num_lanes to 1.
So for a call node with any of the above nodes as one of its value, we
were incorrectly replacing the extract lane node with 4 nodes - it
should only be 1 scalar node.
Drive by fix for LowerShift, it needs to check if the shift value node
has replacement (e.g. if it is an extract lane node).
Also we weren't setting the lowered type of a kPhi node. This can be a
problem if the output of a Phi node is used by a F32x4ExtractLane and
I32x4ExtractLane, which is possible (and type correct since both take
v128). This will require that the output be both a float and a int,
which is impossible. So fix it to Int32x4, and the uses of the phi nodes
will convert appropriately.
Added a test for the call node. Also tested this code by running one of
our benchmarks, which exercises the Phi logic.
Bug: v8:10507
Change-Id: I01a76b349ba9d0e157b64e737bdb4c70f96aa954
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2536952
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71218}
2020-11-17 01:57:58 +00:00
|
|
|
WASM_SIMD_TEST(FunctionCallWithExtractLaneOutputAsArgument) {
|
|
|
|
// This uses the result of an extract lane as an argument to a function call
|
|
|
|
// to exercise lowering for kCall and make sure the the extract lane is
|
|
|
|
// correctly replaced with a scalar.
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
|
|
|
|
WasmFunctionCompiler& fn = r.NewFunction(sigs.f_f());
|
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(fn, WASM_LOCAL_GET(0), WASM_LOCAL_GET(0), kExprF32Add);
|
[wasm-simd][scalar-lowering] Fix replacement for call nodes
all_true, any_true, bitmask, and extract_lane all replace a simd type
with single scalar, so we don't need to set nullptr for the extraneous
lane, and can set num_lanes to 1.
So for a call node with any of the above nodes as one of its value, we
were incorrectly replacing the extract lane node with 4 nodes - it
should only be 1 scalar node.
Drive by fix for LowerShift, it needs to check if the shift value node
has replacement (e.g. if it is an extract lane node).
Also we weren't setting the lowered type of a kPhi node. This can be a
problem if the output of a Phi node is used by a F32x4ExtractLane and
I32x4ExtractLane, which is possible (and type correct since both take
v128). This will require that the output be both a float and a int,
which is impossible. So fix it to Int32x4, and the uses of the phi nodes
will convert appropriately.
Added a test for the call node. Also tested this code by running one of
our benchmarks, which exercises the Phi logic.
Bug: v8:10507
Change-Id: I01a76b349ba9d0e157b64e737bdb4c70f96aa954
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2536952
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71218}
2020-11-17 01:57:58 +00:00
|
|
|
|
2020-12-17 16:55:33 +00:00
|
|
|
BUILD(r, WASM_LOCAL_GET(0), WASM_SIMD_OP(kExprI32x4Splat),
|
[wasm-simd][scalar-lowering] Fix replacement for call nodes
all_true, any_true, bitmask, and extract_lane all replace a simd type
with single scalar, so we don't need to set nullptr for the extraneous
lane, and can set num_lanes to 1.
So for a call node with any of the above nodes as one of its value, we
were incorrectly replacing the extract lane node with 4 nodes - it
should only be 1 scalar node.
Drive by fix for LowerShift, it needs to check if the shift value node
has replacement (e.g. if it is an extract lane node).
Also we weren't setting the lowered type of a kPhi node. This can be a
problem if the output of a Phi node is used by a F32x4ExtractLane and
I32x4ExtractLane, which is possible (and type correct since both take
v128). This will require that the output be both a float and a int,
which is impossible. So fix it to Int32x4, and the uses of the phi nodes
will convert appropriately.
Added a test for the call node. Also tested this code by running one of
our benchmarks, which exercises the Phi logic.
Bug: v8:10507
Change-Id: I01a76b349ba9d0e157b64e737bdb4c70f96aa954
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2536952
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71218}
2020-11-17 01:57:58 +00:00
|
|
|
WASM_SIMD_OP(kExprF32x4ExtractLane), 0, kExprCallFunction,
|
2020-12-17 16:55:33 +00:00
|
|
|
fn.function_index(), WASM_SIMD_OP(kExprF32x4Splat), WASM_LOCAL_GET(0),
|
[wasm-simd][scalar-lowering] Fix replacement for call nodes
all_true, any_true, bitmask, and extract_lane all replace a simd type
with single scalar, so we don't need to set nullptr for the extraneous
lane, and can set num_lanes to 1.
So for a call node with any of the above nodes as one of its value, we
were incorrectly replacing the extract lane node with 4 nodes - it
should only be 1 scalar node.
Drive by fix for LowerShift, it needs to check if the shift value node
has replacement (e.g. if it is an extract lane node).
Also we weren't setting the lowered type of a kPhi node. This can be a
problem if the output of a Phi node is used by a F32x4ExtractLane and
I32x4ExtractLane, which is possible (and type correct since both take
v128). This will require that the output be both a float and a int,
which is impossible. So fix it to Int32x4, and the uses of the phi nodes
will convert appropriately.
Added a test for the call node. Also tested this code by running one of
our benchmarks, which exercises the Phi logic.
Bug: v8:10507
Change-Id: I01a76b349ba9d0e157b64e737bdb4c70f96aa954
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2536952
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71218}
2020-11-17 01:57:58 +00:00
|
|
|
WASM_SIMD_OP(kExprI32x4Splat), WASM_SIMD_OP(kExprI32x4Add),
|
|
|
|
WASM_SIMD_OP(kExprI32x4ExtractLane), 0);
|
|
|
|
CHECK_EQ(15, r.Call(5));
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:48:04 +00:00
|
|
|
} // namespace test_run_wasm_simd
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|