Commit 2f83ffa9 authored by Aseem Garg's avatar Aseem Garg Committed by Commit Bot

[WASM SIMD] Store simd lowering compare ops result as -1 instead of 1

BUG: v8:6020
Change-Id: I3148511233ee6f89acd71644e0c43f72ccc5eef0
Reviewed-on: https://chromium-review.googlesource.com/538160Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Commit-Queue: Aseem Garg <aseemgarg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46071}
parent 323cf26d
......@@ -93,6 +93,16 @@ void SimdScalarLowering::LowerGraph() {
V(I32x4ShrU) \
V(I32x4MinU) \
V(I32x4MaxU) \
V(I32x4Eq) \
V(I32x4Ne) \
V(I32x4LtS) \
V(I32x4LeS) \
V(I32x4GtS) \
V(I32x4GeS) \
V(I32x4LtU) \
V(I32x4LeU) \
V(I32x4GtU) \
V(I32x4GeU) \
V(S128And) \
V(S128Or) \
V(S128Xor) \
......@@ -112,7 +122,7 @@ void SimdScalarLowering::LowerGraph() {
V(F32x4Min) \
V(F32x4Max)
#define FOREACH_FLOAT32X4_TO_SIMD1X4OPCODE(V) \
#define FOREACH_FLOAT32X4_TO_INT32X4OPCODE(V) \
V(F32x4Eq) \
V(F32x4Ne) \
V(F32x4Lt) \
......@@ -120,18 +130,6 @@ void SimdScalarLowering::LowerGraph() {
V(F32x4Gt) \
V(F32x4Ge)
#define FOREACH_INT32X4_TO_SIMD1X4OPCODE(V) \
V(I32x4Eq) \
V(I32x4Ne) \
V(I32x4LtS) \
V(I32x4LeS) \
V(I32x4GtS) \
V(I32x4GeS) \
V(I32x4LtU) \
V(I32x4LeU) \
V(I32x4GtU) \
V(I32x4GeU)
#define FOREACH_INT16X8_OPCODE(V) \
V(I16x8Splat) \
V(I16x8ExtractLane) \
......@@ -150,7 +148,13 @@ void SimdScalarLowering::LowerGraph() {
V(I16x8AddSaturateU) \
V(I16x8SubSaturateU) \
V(I16x8MinU) \
V(I16x8MaxU)
V(I16x8MaxU) \
V(I16x8Eq) \
V(I16x8Ne) \
V(I16x8LtS) \
V(I16x8LeS) \
V(I16x8LtU) \
V(I16x8LeU)
#define FOREACH_INT8X16_OPCODE(V) \
V(I8x16Splat) \
......@@ -170,35 +174,27 @@ void SimdScalarLowering::LowerGraph() {
V(I8x16AddSaturateU) \
V(I8x16SubSaturateU) \
V(I8x16MinU) \
V(I8x16MaxU)
#define FOREACH_INT16X8_TO_SIMD1X8OPCODE(V) \
V(I16x8Eq) \
V(I16x8Ne) \
V(I16x8LtS) \
V(I16x8LeS) \
V(I16x8LtU) \
V(I16x8LeU)
#define FOREACH_INT8X16_TO_SIMD1X16OPCODE(V) \
V(I8x16Eq) \
V(I8x16Ne) \
V(I8x16LtS) \
V(I8x16LeS) \
V(I8x16LtU) \
V(I8x16MaxU) \
V(I8x16Eq) \
V(I8x16Ne) \
V(I8x16LtS) \
V(I8x16LeS) \
V(I8x16LtU) \
V(I8x16LeU)
#define FOREACH_SIMD_TYPE_TO_MACHINE_TYPE(V) \
V(Float32x4, Float32) \
V(Int32x4, Int32) \
V(Int16x8, Int16) \
V(Int8x16, Int8)
#define FOREACH_SIMD_TYPE_TO_MACHINE_REP(V) \
V(Float32x4, Float32) \
V(Int32x4, Word32) \
V(Int16x8, Word16) \
V(Int8x16, Word8)
MachineType SimdScalarLowering::MachineTypeFrom(SimdType simdType) {
switch (simdType) {
case SimdType::kFloat32x4:
return MachineType::Float32();
case SimdType::kInt32x4:
return MachineType::Int32();
case SimdType::kInt16x8:
return MachineType::Int16();
case SimdType::kInt8x16:
return MachineType::Int8();
}
return MachineType::None();
}
void SimdScalarLowering::SetLoweredType(Node* node, Node* output) {
switch (node->opcode()) {
......@@ -214,8 +210,7 @@ void SimdScalarLowering::SetLoweredType(Node* node, Node* output) {
replacements_[node->id()].type = SimdType::kFloat32x4;
break;
}
FOREACH_FLOAT32X4_TO_SIMD1X4OPCODE(CASE_STMT)
FOREACH_INT32X4_TO_SIMD1X4OPCODE(CASE_STMT) {
FOREACH_FLOAT32X4_TO_INT32X4OPCODE(CASE_STMT) {
replacements_[node->id()].type = SimdType::kInt32x4;
break;
}
......@@ -223,27 +218,18 @@ void SimdScalarLowering::SetLoweredType(Node* node, Node* output) {
replacements_[node->id()].type = SimdType::kInt16x8;
break;
}
FOREACH_INT16X8_TO_SIMD1X8OPCODE(CASE_STMT) {
replacements_[node->id()].type = SimdType::kInt16x8;
break;
}
FOREACH_INT8X16_OPCODE(CASE_STMT) {
replacements_[node->id()].type = SimdType::kInt8x16;
break;
}
FOREACH_INT8X16_TO_SIMD1X16OPCODE(CASE_STMT) {
replacements_[node->id()].type = SimdType::kInt8x16;
break;
}
default: {
switch (output->opcode()) {
FOREACH_FLOAT32X4_TO_SIMD1X4OPCODE(CASE_STMT)
case IrOpcode::kF32x4SConvertI32x4:
case IrOpcode::kF32x4UConvertI32x4: {
replacements_[node->id()].type = SimdType::kInt32x4;
break;
}
FOREACH_INT32X4_TO_SIMD1X4OPCODE(CASE_STMT)
FOREACH_FLOAT32X4_TO_INT32X4OPCODE(CASE_STMT)
case IrOpcode::kI32x4SConvertF32x4:
case IrOpcode::kI32x4UConvertF32x4: {
replacements_[node->id()].type = SimdType::kFloat32x4;
......@@ -253,14 +239,6 @@ void SimdScalarLowering::SetLoweredType(Node* node, Node* output) {
replacements_[node->id()].type = SimdType::kInt32x4;
break;
}
FOREACH_INT16X8_TO_SIMD1X8OPCODE(CASE_STMT) {
replacements_[node->id()].type = SimdType::kInt16x8;
break;
}
FOREACH_INT8X16_TO_SIMD1X16OPCODE(CASE_STMT) {
replacements_[node->id()].type = SimdType::kInt8x16;
break;
}
default: {
replacements_[node->id()].type = replacements_[output->id()].type;
}
......@@ -410,18 +388,42 @@ void SimdScalarLowering::LowerStoreOp(MachineRepresentation rep, Node* node,
}
void SimdScalarLowering::LowerBinaryOp(Node* node, SimdType input_rep_type,
const Operator* op, bool invert_inputs) {
const Operator* op) {
DCHECK(node->InputCount() == 2);
Node** rep_left = GetReplacementsWithType(node->InputAt(0), input_rep_type);
Node** rep_right = GetReplacementsWithType(node->InputAt(1), input_rep_type);
int num_lanes = NumLanes(input_rep_type);
Node** rep_node = zone()->NewArray<Node*>(num_lanes);
for (int i = 0; i < num_lanes; ++i) {
rep_node[i] = graph()->NewNode(op, rep_left[i], rep_right[i]);
}
ReplaceNode(node, rep_node, num_lanes);
}
void SimdScalarLowering::LowerCompareOp(Node* node, SimdType input_rep_type,
const Operator* op,
bool invert_inputs) {
DCHECK(node->InputCount() == 2);
Node** rep_left = GetReplacementsWithType(node->InputAt(0), input_rep_type);
Node** rep_right = GetReplacementsWithType(node->InputAt(1), input_rep_type);
int num_lanes = NumLanes(input_rep_type);
Node** rep_node = zone()->NewArray<Node*>(num_lanes);
for (int i = 0; i < num_lanes; ++i) {
Node* cmp_result = nullptr;
if (invert_inputs) {
rep_node[i] = graph()->NewNode(op, rep_right[i], rep_left[i]);
cmp_result = graph()->NewNode(op, rep_right[i], rep_left[i]);
} else {
rep_node[i] = graph()->NewNode(op, rep_left[i], rep_right[i]);
cmp_result = graph()->NewNode(op, rep_left[i], rep_right[i]);
}
Diamond d_cmp(graph(), common(),
graph()->NewNode(machine()->Word32Equal(), cmp_result,
jsgraph_->Int32Constant(0)));
MachineRepresentation rep =
(input_rep_type == SimdType::kFloat32x4)
? MachineRepresentation::kWord32
: MachineTypeFrom(input_rep_type).representation();
rep_node[i] =
d_cmp.Phi(rep, jsgraph_->Int32Constant(0), jsgraph_->Int32Constant(-1));
}
ReplaceNode(node, rep_node, num_lanes);
}
......@@ -677,8 +679,12 @@ void SimdScalarLowering::LowerNotEqual(Node* node, SimdType input_rep_type,
for (int i = 0; i < num_lanes; ++i) {
Diamond d(graph(), common(),
graph()->NewNode(op, rep_left[i], rep_right[i]));
rep_node[i] = d.Phi(MachineRepresentation::kWord32,
jsgraph_->Int32Constant(0), jsgraph_->Int32Constant(1));
MachineRepresentation rep =
(input_rep_type == SimdType::kFloat32x4)
? MachineRepresentation::kWord32
: MachineTypeFrom(input_rep_type).representation();
rep_node[i] =
d.Phi(rep, jsgraph_->Int32Constant(0), jsgraph_->Int32Constant(-1));
}
ReplaceNode(node, rep_node, num_lanes);
}
......@@ -732,17 +738,7 @@ void SimdScalarLowering::LowerNode(Node* node) {
MachineRepresentation rep =
LoadRepresentationOf(node->op()).representation();
const Operator* load_op;
#define LOAD_CASE(sType, mType) \
case SimdType::k##sType: \
load_op = machine()->Load(MachineType::mType()); \
break;
switch (rep_type) {
FOREACH_SIMD_TYPE_TO_MACHINE_TYPE(LOAD_CASE)
default:
UNREACHABLE();
}
#undef LOAD_CASE
load_op = machine()->Load(MachineTypeFrom(rep_type));
LowerLoadOp(rep, node, load_op, rep_type);
break;
}
......@@ -750,17 +746,7 @@ void SimdScalarLowering::LowerNode(Node* node) {
MachineRepresentation rep =
UnalignedLoadRepresentationOf(node->op()).representation();
const Operator* load_op;
#define UNALIGNED_LOAD_CASE(sType, mType) \
case SimdType::k##sType: \
load_op = machine()->UnalignedLoad(MachineType::mType()); \
break;
switch (rep_type) {
FOREACH_SIMD_TYPE_TO_MACHINE_TYPE(UNALIGNED_LOAD_CASE)
default:
UNREACHABLE();
}
#undef UNALIGHNED_LOAD_CASE
load_op = machine()->UnalignedLoad(MachineTypeFrom(rep_type));
LowerLoadOp(rep, node, load_op, rep_type);
break;
}
......@@ -770,35 +756,16 @@ void SimdScalarLowering::LowerNode(Node* node) {
WriteBarrierKind write_barrier_kind =
StoreRepresentationOf(node->op()).write_barrier_kind();
const Operator* store_op;
#define STORE_CASE(sType, mType) \
case SimdType::k##sType: \
store_op = machine()->Store(StoreRepresentation( \
MachineRepresentation::k##mType, write_barrier_kind)); \
break;
switch (rep_type) {
FOREACH_SIMD_TYPE_TO_MACHINE_REP(STORE_CASE)
default:
UNREACHABLE();
}
#undef STORE_CASE
store_op = machine()->Store(StoreRepresentation(
MachineTypeFrom(rep_type).representation(), write_barrier_kind));
LowerStoreOp(rep, node, store_op, rep_type);
break;
}
case IrOpcode::kUnalignedStore: {
MachineRepresentation rep = UnalignedStoreRepresentationOf(node->op());
const Operator* store_op;
#define UNALIGNED_STORE_CASE(sType, mType) \
case SimdType::k##sType: \
store_op = machine()->UnalignedStore(MachineRepresentation::k##mType); \
break;
switch (rep_type) {
FOREACH_SIMD_TYPE_TO_MACHINE_REP(UNALIGNED_STORE_CASE)
default:
UNREACHABLE();
}
#undef UNALIGNED_STORE_CASE
store_op =
machine()->UnalignedStore(MachineTypeFrom(rep_type).representation());
LowerStoreOp(rep, node, store_op, rep_type);
break;
}
......@@ -1045,10 +1012,10 @@ void SimdScalarLowering::LowerNode(Node* node) {
ReplaceNode(node, rep_node, num_lanes);
break;
}
#define COMPARISON_CASE(type, simd_op, lowering_op, invert) \
case IrOpcode::simd_op: { \
LowerBinaryOp(node, SimdType::k##type, machine()->lowering_op(), invert); \
break; \
#define COMPARISON_CASE(type, simd_op, lowering_op, invert) \
case IrOpcode::simd_op: { \
LowerCompareOp(node, SimdType::k##type, machine()->lowering_op(), invert); \
break; \
}
COMPARISON_CASE(Float32x4, kF32x4Eq, Float32Equal, false)
COMPARISON_CASE(Float32x4, kF32x4Lt, Float32LessThan, false)
......@@ -1112,18 +1079,8 @@ void SimdScalarLowering::LowerNode(Node* node) {
Diamond d(graph(), common(),
graph()->NewNode(machine()->Word32Equal(), boolean_input[i],
jsgraph_->Int32Constant(0)));
#define SELECT_CASE(sType, mType) \
case SimdType::k##sType: \
rep_node[i] = \
d.Phi(MachineRepresentation::k##mType, rep_right[1], rep_left[0]); \
break;
switch (rep_type) {
FOREACH_SIMD_TYPE_TO_MACHINE_REP(SELECT_CASE)
default:
UNREACHABLE();
}
#undef SELECT_CASE
rep_node[i] = d.Phi(MachineTypeFrom(rep_type).representation(),
rep_right[1], rep_left[0]);
}
ReplaceNode(node, rep_node, num_lanes);
break;
......@@ -1257,19 +1214,9 @@ void SimdScalarLowering::PreparePhiReplacement(Node* phi) {
}
Node** rep_nodes = zone()->NewArray<Node*>(num_lanes);
for (int i = 0; i < num_lanes; ++i) {
#define PHI_CASE(sType, mType) \
case SimdType::k##sType: \
rep_nodes[i] = graph()->NewNode( \
common()->Phi(MachineRepresentation::k##mType, value_count), \
value_count + 1, inputs_rep[i], false); \
break;
switch (type) {
FOREACH_SIMD_TYPE_TO_MACHINE_REP(PHI_CASE)
default:
UNREACHABLE();
}
#undef PHI_CASE
rep_nodes[i] = graph()->NewNode(
common()->Phi(MachineTypeFrom(type).representation(), value_count),
value_count + 1, inputs_rep[i], false);
}
ReplaceNode(phi, rep_nodes, num_lanes);
}
......
......@@ -73,8 +73,9 @@ class SimdScalarLowering {
const Operator* load_op, SimdType type);
void LowerStoreOp(MachineRepresentation rep, Node* node,
const Operator* store_op, SimdType rep_type);
void LowerBinaryOp(Node* node, SimdType input_rep_type, const Operator* op,
bool invert_inputs = false);
void LowerBinaryOp(Node* node, SimdType input_rep_type, const Operator* op);
void LowerCompareOp(Node* node, SimdType input_rep_type, const Operator* op,
bool invert_inputs = false);
Node* FixUpperBits(Node* input, int32_t shift);
void LowerBinaryOpForSmallInt(Node* node, SimdType input_rep_type,
const Operator* op);
......@@ -88,6 +89,7 @@ class SimdScalarLowering {
void LowerShiftOp(Node* node, SimdType type);
Node* BuildF64Trunc(Node* input);
void LowerNotEqual(Node* node, SimdType input_rep_type, const Operator* op);
MachineType MachineTypeFrom(SimdType simdType);
JSGraph* const jsgraph_;
NodeMarker<State> state_;
......
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