Commit 7a28ee82 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[ptr-compr] Add ChangeTaggedToCompressed case to DecompressionOptimizer

Even though they don't generate any code, it breaks some pattern
matching when these nodes are present (e.g comparisons with compressed
heap objects).

Bug: v8:7703
Change-Id: I9670c2b4e85b1635061b16d4b125de9ff51fd403
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1940153Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65227}
parent 4eee8805
......@@ -13,6 +13,12 @@ namespace compiler {
namespace {
// TODO(v8:7703): ChangeTaggedToCompressed case to be removed when the
// TaggedEqual implementation stops using ChangeTaggedToCompressed.
bool IsChangeTaggedToCompressed(Node* const node) {
return node->opcode() == IrOpcode::kChangeTaggedToCompressed;
}
bool IsMachineLoad(Node* const node) {
const IrOpcode::Value opcode = node->opcode();
return opcode == IrOpcode::kLoad || opcode == IrOpcode::kPoisonedLoad ||
......@@ -37,7 +43,8 @@ bool IsTaggedPhi(Node* const node) {
}
bool CanBeCompressed(Node* const node) {
return IsHeapConstant(node) || IsTaggedMachineLoad(node) || IsTaggedPhi(node);
return IsHeapConstant(node) || IsTaggedMachineLoad(node) ||
IsTaggedPhi(node) || IsChangeTaggedToCompressed(node);
}
} // anonymous namespace
......@@ -217,6 +224,16 @@ void DecompressionOptimizer::ChangeLoad(Node* const node) {
}
}
void DecompressionOptimizer::RemoveChangeTaggedToCompressed(Node* const node) {
DCHECK(IsChangeTaggedToCompressed(node));
Node* input = node->InputAt(0);
// We can safely eliminate a ChangeTaggedToCompressed node if its input is
// going to be changing to compressed in this same Reducer.
if (IsOnly32BitsObserved(input) && CanBeCompressed(input)) {
NodeProperties::ReplaceUses(node, input);
}
}
void DecompressionOptimizer::ChangeNodes() {
for (Node* const node : compressed_candidate_nodes_) {
// compressed_candidate_nodes_ contains all the nodes that once had the
......@@ -227,6 +244,9 @@ void DecompressionOptimizer::ChangeNodes() {
if (IsEverythingObserved(node)) continue;
switch (node->opcode()) {
case IrOpcode::kChangeTaggedToCompressed:
RemoveChangeTaggedToCompressed(node);
break;
case IrOpcode::kHeapConstant:
ChangeHeapConstant(node);
break;
......
......@@ -67,6 +67,10 @@ class V8_EXPORT_PRIVATE DecompressionOptimizer final {
// Change node's load into a compressed one.
void ChangeLoad(Node* const node);
// Remove a ChangeTaggedToCompressed if its input is going to become a
// compressed node.
void RemoveChangeTaggedToCompressed(Node* const node);
// Go through the already marked nodes and changed the operation for the nodes
// that can use compressed outputs.
void ChangeNodes();
......@@ -94,6 +98,10 @@ class V8_EXPORT_PRIVATE DecompressionOptimizer final {
return states_.Get(node) == State::kEverythingObserved;
}
bool IsOnly32BitsObserved(Node* const node) {
return states_.Get(node) == State::kOnly32BitsObserved;
}
Graph* graph() const { return graph_; }
CommonOperatorBuilder* common() const { return common_; }
MachineOperatorBuilder* machine() const { return machine_; }
......
......@@ -121,13 +121,17 @@ TEST_F(DecompressionOptimizerTest, Word32EqualTwoDecompresses) {
effect, control);
Node* change_to_tagged_2 =
graph()->NewNode(machine()->ChangeTaggedToCompressed(), load_2);
graph()->SetEnd(graph()->NewNode(machine()->Word32Equal(),
change_to_tagged_1, change_to_tagged_2));
Node* equal = graph()->NewNode(machine()->Word32Equal(),
change_to_tagged_1, change_to_tagged_2);
graph()->SetEnd(equal);
// Change the nodes, and test the change.
Reduce();
EXPECT_EQ(LoadMachRep(load_1), CompressedMachRep(types[i]));
EXPECT_EQ(LoadMachRep(load_2), CompressedMachRep(types[j]));
// Test that we eliminate the ChangeTaggedToCompressed nodes.
EXPECT_EQ(equal->InputAt(0), load_1);
EXPECT_EQ(equal->InputAt(1), load_2);
}
}
}
......@@ -149,13 +153,16 @@ TEST_F(DecompressionOptimizerTest, Word32EqualDecompressAndConstant) {
graph()->NewNode(machine()->ChangeTaggedToCompressed(), load);
Node* constant =
graph()->NewNode(common()->HeapConstant(heap_constants[j]));
graph()->SetEnd(graph()->NewNode(machine()->Word32Equal(),
change_to_tagged, constant));
Node* equal = graph()->NewNode(machine()->Word32Equal(), change_to_tagged,
constant);
graph()->SetEnd(equal);
// Change the nodes, and test the change.
Reduce();
EXPECT_EQ(LoadMachRep(load), CompressedMachRep(types[i]));
EXPECT_EQ(constant->opcode(), IrOpcode::kCompressedHeapConstant);
// Test that we eliminate the ChangeTaggedToCompressed node.
EXPECT_EQ(equal->InputAt(0), load);
}
}
}
......
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