Commit 23834cbd authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[ptr-compr][Turbofan] Adding the DecompressionElimination AdvancedReducer

After introducing explicit compress and decompress nodes for each load
and store we are left with many nodes that are redundant.

This CL aims to eliminate redundant decompressions and compressions in the
"direct decompression & compression" category.

Also added tests to test the new reducer.

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: I93e024d13af34d484086b7983f379265d16ac154
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1602702Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61473}
parent 37ab663a
......@@ -1757,6 +1757,8 @@ v8_compiler_sources = [
"src/compiler/control-flow-optimizer.h",
"src/compiler/dead-code-elimination.cc",
"src/compiler/dead-code-elimination.h",
"src/compiler/decompression-elimination.cc",
"src/compiler/decompression-elimination.h",
"src/compiler/diamond.h",
"src/compiler/effect-control-linearizer.cc",
"src/compiler/effect-control-linearizer.h",
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/decompression-elimination.h"
namespace v8 {
namespace internal {
namespace compiler {
DecompressionElimination::DecompressionElimination(Editor* editor)
: AdvancedReducer(editor) {}
bool DecompressionElimination::IsValidDecompress(
IrOpcode::Value compressOpcode, IrOpcode::Value decompressOpcode) {
switch (compressOpcode) {
case IrOpcode::kChangeTaggedToCompressed:
return IrOpcode::IsDecompressOpcode(decompressOpcode);
case IrOpcode::kChangeTaggedSignedToCompressedSigned:
return decompressOpcode ==
IrOpcode::kChangeCompressedSignedToTaggedSigned;
case IrOpcode::kChangeTaggedPointerToCompressedPointer:
return decompressOpcode ==
IrOpcode::kChangeCompressedPointerToTaggedPointer ||
decompressOpcode == IrOpcode::kChangeCompressedToTagged;
default:
break;
}
UNREACHABLE();
}
Reduction DecompressionElimination::ReduceCompress(Node* node) {
DCHECK(IrOpcode::IsCompressOpcode(node->opcode()));
DCHECK_EQ(node->InputCount(), 1);
Node* input_node = node->InputAt(0);
if (IrOpcode::IsDecompressOpcode(input_node->opcode())) {
DCHECK(IsValidDecompress(node->opcode(), input_node->opcode()));
DCHECK_EQ(input_node->InputCount(), 1);
return Replace(input_node->InputAt(0));
} else {
return NoChange();
}
}
Reduction DecompressionElimination::Reduce(Node* node) {
DisallowHeapAccess no_heap_access;
switch (node->opcode()) {
case IrOpcode::kChangeTaggedToCompressed:
case IrOpcode::kChangeTaggedSignedToCompressedSigned:
case IrOpcode::kChangeTaggedPointerToCompressedPointer:
return ReduceCompress(node);
default:
break;
}
return NoChange();
}
} // namespace compiler
} // namespace internal
} // namespace v8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_DECOMPRESSION_ELIMINATION_H_
#define V8_COMPILER_DECOMPRESSION_ELIMINATION_H_
#include "src/compiler/graph-reducer.h"
namespace v8 {
namespace internal {
namespace compiler {
// Performs elimination of redundant decompressions within the graph.
class V8_EXPORT_PRIVATE DecompressionElimination final
: public NON_EXPORTED_BASE(AdvancedReducer) {
public:
explicit DecompressionElimination(Editor* editor);
~DecompressionElimination() final = default;
const char* reducer_name() const override {
return "DecompressionElimination";
}
Reduction Reduce(Node* node) final;
private:
// Removes direct Decompressions & Compressions, going from
// Parent <- Decompression <- Compression <- Child
// to
// Parent <- Child
// Can be used for Any, Signed, and Pointer compressions.
Reduction ReduceCompress(Node* node);
// Returns true if the decompress opcode is valid for the compressed one.
bool IsValidDecompress(IrOpcode::Value compressOpcode,
IrOpcode::Value decompressOpcode);
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_DECOMPRESSION_ELIMINATION_H_
......@@ -933,6 +933,18 @@ class V8_EXPORT_PRIVATE IrOpcode {
(kWord32Equal <= value && value <= kFloat64LessThanOrEqual);
}
// Returns true if opcode for decompress operator.
static bool IsDecompressOpcode(Value value) {
return kChangeCompressedToTagged <= value &&
value <= kChangeCompressedSignedToTaggedSigned;
}
// Returns true if opcode for compress operator.
static bool IsCompressOpcode(Value value) {
return kChangeTaggedToCompressed <= value &&
value <= kChangeTaggedSignedToCompressedSigned;
}
static bool IsContextChainExtendingOpcode(Value value) {
return kJSCreateFunctionContext <= value && value <= kJSCreateBlockContext;
}
......
......@@ -35,6 +35,7 @@
#include "src/compiler/constant-folding-reducer.h"
#include "src/compiler/control-flow-optimizer.h"
#include "src/compiler/dead-code-elimination.h"
#include "src/compiler/decompression-elimination.h"
#include "src/compiler/effect-control-linearizer.h"
#include "src/compiler/escape-analysis-reducer.h"
#include "src/compiler/escape-analysis.h"
......@@ -1537,6 +1538,10 @@ struct LateOptimizationPhase {
data->machine(), temp_zone);
SelectLowering select_lowering(data->jsgraph()->graph(),
data->jsgraph()->common());
#ifdef V8_COMPRESS_POINTERS
DecompressionElimination decompression_elimination(&graph_reducer);
AddReducer(data, &graph_reducer, &decompression_elimination);
#endif
AddReducer(data, &graph_reducer, &branch_condition_elimination);
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &machine_reducer);
......
......@@ -102,6 +102,7 @@ v8_source_set("unittests_sources") {
"compiler/control-equivalence-unittest.cc",
"compiler/control-flow-optimizer-unittest.cc",
"compiler/dead-code-elimination-unittest.cc",
"compiler/decompression-elimination-unittest.cc",
"compiler/diamond-unittest.cc",
"compiler/effect-control-linearizer-unittest.cc",
"compiler/graph-reducer-unittest.cc",
......
This diff is collapsed.
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