Commit 389c2e3c authored by Georg Schmid's avatar Georg Schmid Committed by Commit Bot

[ptr-compr] Extend Decompression Elimination to Compress/Decompress pairs

We previously only optimized cases like

  Parent <- Decompression <- Compression <- Child

to

  Parent <- Child

This CL also adds the complementary optimization, namely, it reduces

  Parent <- Compression <- Decompression <- Child

as above.

Such a cases became apparent after a recent extension of CSA load elimination (see https://chromium-review.googlesource.com/c/v8/v8/+/1660626), breaking a load elimination test case and thus the pointer compression build.

R=jarin@chromium.org, solanes@chromium.org

Change-Id: Ic730d05175f214e7055f94704141744ca44fefe5
Bug: v8:9353
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1664070
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62246}
parent ab9f69e1
......@@ -77,6 +77,21 @@ Reduction DecompressionElimination::ReduceCompress(Node* node) {
}
}
Reduction DecompressionElimination::ReduceDecompress(Node* node) {
DCHECK(IrOpcode::IsDecompressOpcode(node->opcode()));
DCHECK_EQ(node->InputCount(), 1);
Node* input_node = node->InputAt(0);
IrOpcode::Value input_opcode = input_node->opcode();
if (IrOpcode::IsCompressOpcode(input_opcode)) {
DCHECK(IsValidDecompress(input_opcode, node->opcode()));
DCHECK_EQ(input_node->InputCount(), 1);
return Replace(input_node->InputAt(0));
} else {
return NoChange();
}
}
Reduction DecompressionElimination::ReducePhi(Node* node) {
DCHECK_EQ(node->opcode(), IrOpcode::kPhi);
......@@ -197,6 +212,10 @@ Reduction DecompressionElimination::Reduce(Node* node) {
case IrOpcode::kChangeTaggedSignedToCompressedSigned:
case IrOpcode::kChangeTaggedPointerToCompressedPointer:
return ReduceCompress(node);
case IrOpcode::kChangeCompressedToTagged:
case IrOpcode::kChangeCompressedSignedToTaggedSigned:
case IrOpcode::kChangeCompressedPointerToTaggedPointer:
return ReduceDecompress(node);
case IrOpcode::kPhi:
return ReducePhi(node);
case IrOpcode::kTypedStateValues:
......
......@@ -48,6 +48,9 @@ class V8_EXPORT_PRIVATE DecompressionElimination final
// Can be used for Any, Signed, and Pointer compressions.
Reduction ReduceCompress(Node* node);
// Removes direct Compressions & Decompressions, analogously to ReduceCompress
Reduction ReduceDecompress(Node* 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);
......
......@@ -393,6 +393,39 @@ TEST_F(DecompressionEliminationTest,
}
}
// -----------------------------------------------------------------------------
// Direct Compression & Decompression
TEST_F(DecompressionEliminationTest, BasicCompressionDecompression) {
// Skip test if pointer compression is not enabled
if (!COMPRESS_POINTERS_BOOL) {
return;
}
// Define variables
Node* const control = graph()->start();
Node* object = Parameter(Type::Any(), 0);
Node* effect = graph()->start();
Node* index = Parameter(Type::UnsignedSmall(), 1);
ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(),
MachineType::AnyTagged(), kNoWriteBarrier};
// Create the graph
Node* load = graph()->NewNode(simplified()->LoadElement(access), object,
index, effect, control);
Node* changeToCompressed =
graph()->NewNode(machine()->ChangeTaggedToCompressed(), load);
Node* changeToTagged = graph()->NewNode(machine()->ChangeCompressedToTagged(),
changeToCompressed);
effect = graph()->NewNode(simplified()->StoreElement(access), object, index,
changeToTagged, effect, control);
// Reduce
Reduction r = Reduce(changeToTagged);
ASSERT_TRUE(r.Changed());
EXPECT_EQ(load, r.replacement());
}
// -----------------------------------------------------------------------------
// Phi
......
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