Commit 8306b26a authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[ptr-compr][turbofan] Adding Phi reductions to DecompressionElimination

This reduction replaces the Phi's input decompressions with their parent
node, if and only if all of the Phi's inputs are Decompress nodes.

Also, if we have different Decompress nodes as inputs, we need to use
a conservative decompression after the Phi.

Cq-Include-Trybots: luci.v8.try:v8_linux64_pointer_compression_rel_ng
Cq-Include-Trybots: luci.v8.try:v8_linux64_arm64_pointer_compression_rel_ng
Bug: v8:8977, v8:7703
Change-Id: I8cc0264f9d08fe5ad25364f18c9f305afc54529c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1624785Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61820}
parent d47db126
...@@ -79,6 +79,63 @@ Reduction DecompressionElimination::ReduceCompress(Node* node) { ...@@ -79,6 +79,63 @@ Reduction DecompressionElimination::ReduceCompress(Node* node) {
} }
} }
Reduction DecompressionElimination::ReducePhi(Node* node) {
DCHECK_EQ(node->opcode(), IrOpcode::kPhi);
const int value_input_count = node->op()->ValueInputCount();
// Check if all input are decompress nodes, and if all are the same.
bool same_decompresses = true;
IrOpcode::Value first_opcode = node->InputAt(0)->opcode();
for (int i = 0; i < value_input_count; ++i) {
Node* input = node->InputAt(i);
if (IrOpcode::IsDecompressOpcode(input->opcode())) {
same_decompresses &= first_opcode == input->opcode();
} else {
return NoChange();
}
}
// By now, we know that all inputs are decompress nodes. If all are the same,
// we can grab the first one to be used after the Phi. If we have different
// Decompress nodes as inputs, we need to use a conservative decompression
// after the Phi.
const Operator* op;
if (same_decompresses) {
op = node->InputAt(0)->op();
} else {
op = machine()->ChangeCompressedToTagged();
}
// Rewire phi's inputs to be the compressed inputs.
for (int i = 0; i < value_input_count; ++i) {
Node* input = node->InputAt(i);
DCHECK_EQ(input->InputCount(), 1);
node->ReplaceInput(i, input->InputAt(0));
}
// Update the MachineRepresentation on the Phi.
MachineRepresentation rep;
switch (op->opcode()) {
case IrOpcode::kChangeCompressedToTagged:
rep = MachineRepresentation::kCompressed;
break;
case IrOpcode::kChangeCompressedSignedToTaggedSigned:
rep = MachineRepresentation::kCompressedSigned;
break;
case IrOpcode::kChangeCompressedPointerToTaggedPointer:
rep = MachineRepresentation::kCompressedPointer;
break;
default:
UNREACHABLE();
}
NodeProperties::ChangeOp(node, common()->Phi(rep, value_input_count));
// Add a decompress after the Phi. To do this, we need to replace the Phi with
// "Phi <- Decompress".
return Replace(graph()->NewNode(op, node));
}
Reduction DecompressionElimination::ReduceTypedStateValues(Node* node) { Reduction DecompressionElimination::ReduceTypedStateValues(Node* node) {
DCHECK_EQ(node->opcode(), IrOpcode::kTypedStateValues); DCHECK_EQ(node->opcode(), IrOpcode::kTypedStateValues);
...@@ -139,6 +196,8 @@ Reduction DecompressionElimination::Reduce(Node* node) { ...@@ -139,6 +196,8 @@ Reduction DecompressionElimination::Reduce(Node* node) {
case IrOpcode::kChangeTaggedSignedToCompressedSigned: case IrOpcode::kChangeTaggedSignedToCompressedSigned:
case IrOpcode::kChangeTaggedPointerToCompressedPointer: case IrOpcode::kChangeTaggedPointerToCompressedPointer:
return ReduceCompress(node); return ReduceCompress(node);
case IrOpcode::kPhi:
return ReducePhi(node);
case IrOpcode::kTypedStateValues: case IrOpcode::kTypedStateValues:
return ReduceTypedStateValues(node); return ReduceTypedStateValues(node);
case IrOpcode::kWord64Equal: case IrOpcode::kWord64Equal:
......
...@@ -48,7 +48,11 @@ class V8_EXPORT_PRIVATE DecompressionElimination final ...@@ -48,7 +48,11 @@ class V8_EXPORT_PRIVATE DecompressionElimination final
// Can be used for Any, Signed, and Pointer compressions. // Can be used for Any, Signed, and Pointer compressions.
Reduction ReduceCompress(Node* node); Reduction ReduceCompress(Node* node);
// Replaces TypedStateValues's input decompressions with their parent node. // Replaces Phi's input decompressions with their input node, if and only if
// all of the Phi's inputs are Decompress nodes.
Reduction ReducePhi(Node* node);
// Replaces TypedStateValues's input decompressions with their input node.
Reduction ReduceTypedStateValues(Node* node); Reduction ReduceTypedStateValues(Node* node);
// Replaces a Word64Equal with a Word32Equal if both of its inputs are // Replaces a Word64Equal with a Word32Equal if both of its inputs are
......
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