[wasm-gc] Add missing types to Int64Lowering

Drive-by: Make the code less verbose my returning the input node from
SetInt32Type.

Bug: v8:7748, chromium:1332385
Change-Id: I2fde9c2168af1365e305e7e8d894b03487e8a8d9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3687692
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80970}
This commit is contained in:
Manos Koukoutos 2022-06-03 06:47:54 +00:00 committed by V8 LUCI CQ
parent 886838b9cd
commit c202e30109
2 changed files with 74 additions and 104 deletions

View File

@ -127,12 +127,14 @@ int GetReturnCountAfterLowering(Signature<MachineRepresentation>* signature) {
} // namespace } // namespace
void Int64Lowering::SetInt32Type(Node* node) { Node* Int64Lowering::SetInt32Type(Node* node) {
NodeProperties::SetType(node, int32_type_); NodeProperties::SetType(node, int32_type_);
return node;
} }
void Int64Lowering::SetFloat64Type(Node* node) { Node* Int64Lowering::SetFloat64Type(Node* node) {
NodeProperties::SetType(node, float64_type_); NodeProperties::SetType(node, float64_type_);
return node;
} }
void Int64Lowering::LowerWord64AtomicBinop(Node* node, const Operator* op) { void Int64Lowering::LowerWord64AtomicBinop(Node* node, const Operator* op) {
@ -142,7 +144,6 @@ void Int64Lowering::LowerWord64AtomicBinop(Node* node, const Operator* op) {
node->ReplaceInput(2, GetReplacementLow(value)); node->ReplaceInput(2, GetReplacementLow(value));
node->InsertInput(zone(), 3, GetReplacementHigh(value)); node->InsertInput(zone(), 3, GetReplacementHigh(value));
NodeProperties::ChangeOp(node, op); NodeProperties::ChangeOp(node, op);
SetInt32Type(node);
ReplaceNodeWithProjections(node); ReplaceNodeWithProjections(node);
} }
@ -204,9 +205,7 @@ void Int64Lowering::LowerLoadOperator(Node* node, MachineRepresentation rep,
} }
node->ReplaceInput(1, index_low); node->ReplaceInput(1, index_low);
NodeProperties::ChangeOp(node, load_op); NodeProperties::ChangeOp(node, load_op);
SetInt32Type(node); ReplaceNode(node, SetInt32Type(node), SetInt32Type(high_node));
SetInt32Type(high_node);
ReplaceNode(node, node, high_node);
} else { } else {
DefaultLowering(node); DefaultLowering(node);
} }
@ -362,10 +361,9 @@ void Int64Lowering::LowerNode(Node* node) {
if (signature()->GetParam(old_index) == if (signature()->GetParam(old_index) ==
MachineRepresentation::kWord64) { MachineRepresentation::kWord64) {
Node* high_node = graph()->NewNode(common()->Parameter(new_index + 1),
graph()->start());
SetInt32Type(node); SetInt32Type(node);
SetInt32Type(high_node); Node* high_node = SetInt32Type(graph()->NewNode(
common()->Parameter(new_index + 1), graph()->start()));
ReplaceNode(node, node, high_node); ReplaceNode(node, node, high_node);
} }
} }
@ -429,9 +427,9 @@ void Int64Lowering::LowerNode(Node* node) {
} }
if (call_descriptor->GetReturnType(old_index).representation() == if (call_descriptor->GetReturnType(old_index).representation() ==
MachineRepresentation::kWord64) { MachineRepresentation::kWord64) {
Node* high_node = graph()->NewNode( Node* high_node = SetInt32Type(graph()->NewNode(
common()->Projection(new_index + 1), node, graph()->start()); common()->Projection(new_index + 1), node, graph()->start()));
ReplaceNode(use_node, use_node, high_node); ReplaceNode(use_node, SetInt32Type(use_node), high_node);
++new_index; ++new_index;
} }
} }
@ -444,14 +442,12 @@ void Int64Lowering::LowerNode(Node* node) {
Node* left = node->InputAt(0); Node* left = node->InputAt(0);
Node* right = node->InputAt(1); Node* right = node->InputAt(1);
Node* low_node = Node* low_node = SetInt32Type(graph()->NewNode(machine()->Word32And(),
graph()->NewNode(machine()->Word32And(), GetReplacementLow(left), GetReplacementLow(left),
GetReplacementLow(right)); GetReplacementLow(right)));
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Word32And(), GetReplacementHigh(left), graph()->NewNode(machine()->Word32And(), GetReplacementHigh(left),
GetReplacementHigh(right)); GetReplacementHigh(right)));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
break; break;
} }
@ -515,14 +511,12 @@ void Int64Lowering::LowerNode(Node* node) {
Node* left = node->InputAt(0); Node* left = node->InputAt(0);
Node* right = node->InputAt(1); Node* right = node->InputAt(1);
Node* low_node = Node* low_node = SetInt32Type(graph()->NewNode(machine()->Word32Or(),
graph()->NewNode(machine()->Word32Or(), GetReplacementLow(left), GetReplacementLow(left),
GetReplacementLow(right)); GetReplacementLow(right)));
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Word32Or(), GetReplacementHigh(left), graph()->NewNode(machine()->Word32Or(), GetReplacementHigh(left),
GetReplacementHigh(right)); GetReplacementHigh(right)));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
break; break;
} }
@ -531,14 +525,12 @@ void Int64Lowering::LowerNode(Node* node) {
Node* left = node->InputAt(0); Node* left = node->InputAt(0);
Node* right = node->InputAt(1); Node* right = node->InputAt(1);
Node* low_node = Node* low_node = SetInt32Type(graph()->NewNode(machine()->Word32Xor(),
graph()->NewNode(machine()->Word32Xor(), GetReplacementLow(left), GetReplacementLow(left),
GetReplacementLow(right)); GetReplacementLow(right)));
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Word32Xor(), GetReplacementHigh(left), graph()->NewNode(machine()->Word32Xor(), GetReplacementHigh(left),
GetReplacementHigh(right)); GetReplacementHigh(right)));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
break; break;
} }
@ -617,9 +609,7 @@ void Int64Lowering::LowerNode(Node* node) {
graph()->NewNode(machine()->Word32Xor(), GetReplacementHigh(left), graph()->NewNode(machine()->Word32Xor(), GetReplacementHigh(left),
GetReplacementHigh(right))), GetReplacementHigh(right))),
graph()->NewNode(common()->Int32Constant(0))); graph()->NewNode(common()->Int32Constant(0)));
ReplaceNode(node, SetInt32Type(replacement), nullptr);
SetInt32Type(replacement);
ReplaceNode(node, replacement, nullptr);
break; break;
} }
case IrOpcode::kInt64LessThan: { case IrOpcode::kInt64LessThan: {
@ -650,10 +640,9 @@ void Int64Lowering::LowerNode(Node* node) {
input = GetReplacementLow(input); input = GetReplacementLow(input);
} }
// We use SAR to preserve the sign in the high word. // We use SAR to preserve the sign in the high word.
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Word32Sar(), input, graph()->NewNode(machine()->Word32Sar(), input,
graph()->NewNode(common()->Int32Constant(31))); graph()->NewNode(common()->Int32Constant(31))));
SetInt32Type(high_node);
ReplaceNode(node, input, high_node); ReplaceNode(node, input, high_node);
node->NullAllInputs(); node->NullAllInputs();
break; break;
@ -689,12 +678,10 @@ void Int64Lowering::LowerNode(Node* node) {
input = GetReplacementLow(input); input = GetReplacementLow(input);
} }
Node* low_node = Node* low_node = SetInt32Type(
graph()->NewNode(machine()->Float64ExtractLowWord32(), input); graph()->NewNode(machine()->Float64ExtractLowWord32(), input));
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Float64ExtractHighWord32(), input); graph()->NewNode(machine()->Float64ExtractHighWord32(), input));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
break; break;
} }
@ -738,16 +725,14 @@ void Int64Lowering::LowerNode(Node* node) {
bool is_ror = node->opcode() == IrOpcode::kWord64RorLowerable; bool is_ror = node->opcode() == IrOpcode::kWord64RorLowerable;
if (!is_ror) std::swap(op1, op2); if (!is_ror) std::swap(op1, op2);
Node* low_node = Node* low_node = SetInt32Type(
graph()->NewNode(machine()->Word32Or(), graph()->NewNode(machine()->Word32Or(),
graph()->NewNode(op1, low_input, masked_shift), graph()->NewNode(op1, low_input, masked_shift),
graph()->NewNode(op2, high_input, inv_shift)); graph()->NewNode(op2, high_input, inv_shift)));
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Word32Or(), graph()->NewNode(machine()->Word32Or(),
graph()->NewNode(op1, high_input, masked_shift), graph()->NewNode(op1, high_input, masked_shift),
graph()->NewNode(op2, low_input, inv_shift)); graph()->NewNode(op2, low_input, inv_shift)));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
} }
} else { } else {
@ -812,16 +797,14 @@ void Int64Lowering::LowerNode(Node* node) {
auto* mask2 = inv_mask; auto* mask2 = inv_mask;
if (!is_ror) std::swap(mask1, mask2); if (!is_ror) std::swap(mask1, mask2);
Node* low_node = graph()->NewNode( Node* low_node = SetInt32Type(graph()->NewNode(
machine()->Word32Or(), machine()->Word32Or(),
graph()->NewNode(machine()->Word32And(), rotate_low, mask1), graph()->NewNode(machine()->Word32And(), rotate_low, mask1),
graph()->NewNode(machine()->Word32And(), rotate_high, mask2)); graph()->NewNode(machine()->Word32And(), rotate_high, mask2)));
Node* high_node = graph()->NewNode( Node* high_node = SetInt32Type(graph()->NewNode(
machine()->Word32Or(), machine()->Word32Or(),
graph()->NewNode(machine()->Word32And(), rotate_high, mask1), graph()->NewNode(machine()->Word32And(), rotate_high, mask1),
graph()->NewNode(machine()->Word32And(), rotate_low, mask2)); graph()->NewNode(machine()->Word32And(), rotate_low, mask2)));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
} }
break; break;
@ -842,8 +825,8 @@ void Int64Lowering::LowerNode(Node* node) {
GetReplacementLow(input)), GetReplacementLow(input)),
graph()->NewNode(common()->Int32Constant(32))), graph()->NewNode(common()->Int32Constant(32))),
graph()->NewNode(machine()->Word32Clz(), GetReplacementHigh(input))); graph()->NewNode(machine()->Word32Clz(), GetReplacementHigh(input)));
SetInt32Type(low_node); ReplaceNode(node, SetInt32Type(low_node),
ReplaceNode(node, low_node, graph()->NewNode(common()->Int32Constant(0))); SetInt32Type(graph()->NewNode(common()->Int32Constant(0))));
break; break;
} }
case IrOpcode::kWord64CtzLowerable: { case IrOpcode::kWord64CtzLowerable: {
@ -864,8 +847,8 @@ void Int64Lowering::LowerNode(Node* node) {
graph()->NewNode(common()->Int32Constant(32))), graph()->NewNode(common()->Int32Constant(32))),
graph()->NewNode(machine()->Word32Ctz().op(), graph()->NewNode(machine()->Word32Ctz().op(),
GetReplacementLow(input))); GetReplacementLow(input)));
SetInt32Type(low_node); ReplaceNode(node, SetInt32Type(low_node),
ReplaceNode(node, low_node, graph()->NewNode(common()->Int32Constant(0))); SetInt32Type(graph()->NewNode(common()->Int32Constant(0))));
break; break;
} }
case IrOpcode::kWord64Ror: case IrOpcode::kWord64Ror:
@ -886,8 +869,8 @@ void Int64Lowering::LowerNode(Node* node) {
GetReplacementLow(input)), GetReplacementLow(input)),
graph()->NewNode(machine()->Word32Popcnt().op(), graph()->NewNode(machine()->Word32Popcnt().op(),
GetReplacementHigh(input))); GetReplacementHigh(input)));
SetInt32Type(low_node); ReplaceNode(node, SetInt32Type(low_node),
ReplaceNode(node, low_node, graph()->NewNode(common()->Int32Constant(0))); SetInt32Type(graph()->NewNode(common()->Int32Constant(0))));
break; break;
} }
case IrOpcode::kPhi: { case IrOpcode::kPhi: {
@ -909,14 +892,12 @@ void Int64Lowering::LowerNode(Node* node) {
case IrOpcode::kLoopExitValue: { case IrOpcode::kLoopExitValue: {
MachineRepresentation rep = LoopExitValueRepresentationOf(node->op()); MachineRepresentation rep = LoopExitValueRepresentationOf(node->op());
if (rep == MachineRepresentation::kWord64) { if (rep == MachineRepresentation::kWord64) {
Node* low_node = graph()->NewNode( Node* low_node = SetInt32Type(graph()->NewNode(
common()->LoopExitValue(MachineRepresentation::kWord32), common()->LoopExitValue(MachineRepresentation::kWord32),
GetReplacementLow(node->InputAt(0)), node->InputAt(1)); GetReplacementLow(node->InputAt(0)), node->InputAt(1)));
Node* high_node = graph()->NewNode( Node* high_node = SetInt32Type(graph()->NewNode(
common()->LoopExitValue(MachineRepresentation::kWord32), common()->LoopExitValue(MachineRepresentation::kWord32),
GetReplacementHigh(node->InputAt(0)), node->InputAt(1)); GetReplacementHigh(node->InputAt(0)), node->InputAt(1)));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
} else { } else {
DefaultLowering(node); DefaultLowering(node);
@ -925,12 +906,10 @@ void Int64Lowering::LowerNode(Node* node) {
} }
case IrOpcode::kWord64ReverseBytes: { case IrOpcode::kWord64ReverseBytes: {
Node* input = node->InputAt(0); Node* input = node->InputAt(0);
Node* low_node = graph()->NewNode(machine()->Word32ReverseBytes(), Node* low_node = SetInt32Type(graph()->NewNode(
GetReplacementHigh(input)); machine()->Word32ReverseBytes(), GetReplacementHigh(input)));
Node* high_node = graph()->NewNode(machine()->Word32ReverseBytes(), Node* high_node = SetInt32Type(graph()->NewNode(
GetReplacementLow(input)); machine()->Word32ReverseBytes(), GetReplacementLow(input)));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
break; break;
} }
@ -941,14 +920,12 @@ void Int64Lowering::LowerNode(Node* node) {
input = GetReplacementLow(input); input = GetReplacementLow(input);
} }
// Sign extend low node to Int32 // Sign extend low node to Int32
Node* low_node = Node* low_node = SetInt32Type(
graph()->NewNode(machine()->SignExtendWord8ToInt32(), input); graph()->NewNode(machine()->SignExtendWord8ToInt32(), input));
// We use SAR to preserve the sign in the high word. // We use SAR to preserve the sign in the high word.
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Word32Sar(), low_node, graph()->NewNode(machine()->Word32Sar(), low_node,
graph()->NewNode(common()->Int32Constant(31))); graph()->NewNode(common()->Int32Constant(31))));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
node->NullAllInputs(); node->NullAllInputs();
break; break;
@ -960,14 +937,12 @@ void Int64Lowering::LowerNode(Node* node) {
input = GetReplacementLow(input); input = GetReplacementLow(input);
} }
// Sign extend low node to Int32 // Sign extend low node to Int32
Node* low_node = Node* low_node = SetInt32Type(
graph()->NewNode(machine()->SignExtendWord16ToInt32(), input); graph()->NewNode(machine()->SignExtendWord16ToInt32(), input));
// We use SAR to preserve the sign in the high word. // We use SAR to preserve the sign in the high word.
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->Word32Sar(), low_node, graph()->NewNode(machine()->Word32Sar(), low_node,
graph()->NewNode(common()->Int32Constant(31))); graph()->NewNode(common()->Int32Constant(31))));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
node->NullAllInputs(); node->NullAllInputs();
break; break;
@ -982,8 +957,8 @@ void Int64Lowering::LowerNode(Node* node) {
ReplaceNodeWithProjections(node); ReplaceNodeWithProjections(node);
} else { } else {
NodeProperties::ChangeOp(node, machine()->Word32AtomicLoad(params)); NodeProperties::ChangeOp(node, machine()->Word32AtomicLoad(params));
SetInt32Type(node); ReplaceNode(node, SetInt32Type(node),
ReplaceNode(node, node, graph()->NewNode(common()->Int32Constant(0))); SetInt32Type(graph()->NewNode(common()->Int32Constant(0))));
} }
break; break;
} }
@ -1039,8 +1014,8 @@ void Int64Lowering::LowerNode(Node* node) {
DefaultLowering(node, true); DefaultLowering(node, true);
NodeProperties::ChangeOp(node, NodeProperties::ChangeOp(node,
machine()->Word32AtomicCompareExchange(type)); machine()->Word32AtomicCompareExchange(type));
SetInt32Type(node); ReplaceNode(node, SetInt32Type(node),
ReplaceNode(node, node, graph()->NewNode(common()->Int32Constant(0))); SetInt32Type(graph()->NewNode(common()->Int32Constant(0))));
} }
break; break;
} }
@ -1056,12 +1031,10 @@ void Int64Lowering::LowerNode(Node* node) {
DCHECK_EQ(1, node->InputCount()); DCHECK_EQ(1, node->InputCount());
Node* input = node->InputAt(0); Node* input = node->InputAt(0);
int32_t lane = OpParameter<int32_t>(node->op()); int32_t lane = OpParameter<int32_t>(node->op());
Node* low_node = Node* low_node = SetInt32Type(
graph()->NewNode(machine()->I32x4ExtractLane(lane * 2), input); graph()->NewNode(machine()->I32x4ExtractLane(lane * 2), input));
Node* high_node = Node* high_node = SetInt32Type(
graph()->NewNode(machine()->I32x4ExtractLane(lane * 2 + 1), input); graph()->NewNode(machine()->I32x4ExtractLane(lane * 2 + 1), input));
SetInt32Type(low_node);
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node); ReplaceNode(node, low_node, high_node);
break; break;
} }
@ -1094,8 +1067,7 @@ void Int64Lowering::LowerComparison(Node* node, const Operator* high_word_op,
GetReplacementHigh(right)), GetReplacementHigh(right)),
graph()->NewNode(low_word_op, GetReplacementLow(left), graph()->NewNode(low_word_op, GetReplacementLow(left),
GetReplacementLow(right)))); GetReplacementLow(right))));
SetInt32Type(replacement); ReplaceNode(node, SetInt32Type(replacement), nullptr);
ReplaceNode(node, replacement, nullptr);
} }
bool Int64Lowering::DefaultLowering(Node* node, bool low_word_only) { bool Int64Lowering::DefaultLowering(Node* node, bool low_word_only) {
@ -1184,9 +1156,7 @@ void Int64Lowering::ReplaceNodeWithProjections(Node* node) {
graph()->NewNode(common()->Projection(0), node, graph()->start()); graph()->NewNode(common()->Projection(0), node, graph()->start());
Node* high_node = Node* high_node =
graph()->NewNode(common()->Projection(1), node, graph()->start()); graph()->NewNode(common()->Projection(1), node, graph()->start());
SetInt32Type(low_node); ReplaceNode(node, SetInt32Type(low_node), SetInt32Type(high_node));
SetInt32Type(high_node);
ReplaceNode(node, low_node, high_node);
} }
void Int64Lowering::LowerMemoryBaseAndIndex(Node* node) { void Int64Lowering::LowerMemoryBaseAndIndex(Node* node) {

View File

@ -73,8 +73,8 @@ class V8_EXPORT_PRIVATE Int64Lowering {
const CallDescriptor* LowerCallDescriptor( const CallDescriptor* LowerCallDescriptor(
const CallDescriptor* call_descriptor); const CallDescriptor* call_descriptor);
void SetInt32Type(Node* node); Node* SetInt32Type(Node* node);
void SetFloat64Type(Node* node); Node* SetFloat64Type(Node* node);
void ReplaceNode(Node* old, Node* new_low, Node* new_high); void ReplaceNode(Node* old, Node* new_low, Node* new_high);
bool HasReplacementLow(Node* node); bool HasReplacementLow(Node* node);