Commit 5f7e9234 authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm-simd][scalar-lowering] Fix lowering for i64x2

Add lowering for I64x2 in S128Const and converting Int64x2 to
Int32x2.

Bug: v8:10507
Change-Id: I5bc40ae135fa00e31e901337b1a315f6ead14b02
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2410800Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69960}
parent a0e38f31
......@@ -1235,6 +1235,15 @@ void SimdScalarLowering::LowerNode(Node* node) {
}
break;
}
case SimdType::kInt64x2: {
uint64_t val[kNumLanes64];
memcpy(val, params.data(), kSimd128Size);
for (int i = 0; i < num_lanes; ++i) {
rep_node[i] = mcgraph_->Int64Constant(
base::ReadLittleEndianValue<uint64_t>(&val[i]));
}
break;
}
case SimdType::kFloat32x4: {
float val[kNumLanes32];
memcpy(val, params.data(), kSimd128Size);
......@@ -1358,6 +1367,7 @@ void SimdScalarLowering::LowerNode(Node* node) {
switch (ReplacementType(input)) {
case SimdType::kInt8x16:
case SimdType::kInt16x8:
case SimdType::kInt64x2:
case SimdType::kFloat32x4: {
Node** reps = GetReplacementsWithType(input, rep_type);
ReplaceNode(input, reps, NumLanes(rep_type));
......@@ -1940,7 +1950,8 @@ void SimdScalarLowering::LowerNode(Node* node) {
DCHECK(ReplacementType(node->InputAt(0)) == SimdType::kInt32x4 ||
ReplacementType(node->InputAt(0)) == SimdType::kInt16x8 ||
ReplacementType(node->InputAt(0)) == SimdType::kInt8x16);
Node** boolean_input = GetReplacements(node->InputAt(0));
Node** boolean_input =
GetReplacementsWithType(node->InputAt(0), rep_type);
Node** rep_left = GetReplacementsWithType(node->InputAt(1), rep_type);
Node** rep_right = GetReplacementsWithType(node->InputAt(2), rep_type);
Node** rep_node = zone()->NewArray<Node*>(num_lanes);
......@@ -2238,6 +2249,20 @@ void SimdScalarLowering::SmallerIntToInt32(Node** replacements, Node** result) {
}
}
void SimdScalarLowering::Int32ToInt64(Node** replacements, Node** result) {
const int num_ints = sizeof(int64_t) / sizeof(int32_t);
for (int i = 0; i < kNumLanes64; i++) {
Node* i64 = graph()->NewNode(machine()->ChangeUint32ToUint64(),
replacements[num_ints * i + 1]);
Node* high = graph()->NewNode(machine()->Word64Shl(), i64,
mcgraph_->Int32Constant(32));
Node* i64_low = graph()->NewNode(machine()->ChangeUint32ToUint64(),
replacements[num_ints * i]);
result[i] = graph()->NewNode(machine()->Word64Or(), high, i64_low);
}
}
Node** SimdScalarLowering::GetReplacementsWithType(Node* node, SimdType type) {
Node** replacements = GetReplacements(node);
if (ReplacementType(node) == type) {
......@@ -2245,7 +2270,11 @@ Node** SimdScalarLowering::GetReplacementsWithType(Node* node, SimdType type) {
}
int num_lanes = NumLanes(type);
Node** result = zone()->NewArray<Node*>(num_lanes);
if (type == SimdType::kInt32x4) {
if (type == SimdType::kInt64x2) {
if (ReplacementType(node) == SimdType::kInt32x4) {
Int32ToInt64(replacements, result);
}
} else if (type == SimdType::kInt32x4) {
if (ReplacementType(node) == SimdType::kInt64x2) {
Int64ToInt32(replacements, result);
} else if (ReplacementType(node) == SimdType::kFloat32x4) {
......
......@@ -82,6 +82,7 @@ class SimdScalarLowering {
void Int32ToSmallerInt(Node** replacements, Node** result);
template <typename T>
void SmallerIntToInt32(Node** replacements, Node** result);
void Int32ToInt64(Node** replacements, Node** result);
Node** GetReplacementsWithType(Node* node, SimdType type);
SimdType ReplacementType(Node* node);
void PreparePhiReplacement(Node* phi);
......
......@@ -103,6 +103,25 @@ WASM_SIMD_TEST(I16x8_Call_Return) {
CHECK_EQ(2, r.Call(1));
}
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,
WASM_SIMD_BINOP(kExprI64x2Add, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
BUILD(r,
WASM_SIMD_I64x2_EXTRACT_LANE(
0, WASM_CALL_FUNCTION(fn.function_index(),
WASM_SIMD_I64x2_SPLAT(WASM_GET_LOCAL(0)),
WASM_SIMD_I64x2_SPLAT(WASM_GET_LOCAL(0)))));
CHECK_EQ(2, r.Call(1));
}
WASM_SIMD_TEST(I8x16Eq_ToTest_S128Const) {
// Test implementation of S128Const in scalar lowering, this test case was
// causing a crash.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment