From 58a64478146b2476ae7bd74e9b077577b5d17c21 Mon Sep 17 00:00:00 2001 From: Santiago Aboy Solanes Date: Tue, 9 Jul 2019 16:41:18 +0100 Subject: [PATCH] [ptr-compr][turbofan] Specialize Word32 -> CompressedSigned conversion Reverse specialization of https://chromium-review.googlesource.com/c/v8/v8/+/1684075. Again, it skips over Tagged to save some instructions. 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:7703 Change-Id: I7fc50e0d8eebfef7a1ba02ce3d687ff808f30680 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1693007 Reviewed-by: Sigurd Schneider Commit-Queue: Santiago Aboy Solanes Cr-Commit-Position: refs/heads/master@{#62645} --- src/compiler/effect-control-linearizer.cc | 15 +++++++++++++++ src/compiler/opcodes.h | 1 + src/compiler/representation-change.cc | 10 +++++++--- src/compiler/simplified-operator.cc | 1 + src/compiler/simplified-operator.h | 1 + src/compiler/verifier.cc | 1 + .../cctest/compiler/test-representation-change.cc | 3 +++ 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/compiler/effect-control-linearizer.cc b/src/compiler/effect-control-linearizer.cc index dc927c65f7..b79ec0206e 100644 --- a/src/compiler/effect-control-linearizer.cc +++ b/src/compiler/effect-control-linearizer.cc @@ -51,6 +51,7 @@ class EffectControlLinearizer { bool TryWireInStateEffect(Node* node, Node* frame_state, Node** effect, Node** control); Node* LowerChangeBitToTagged(Node* node); + Node* LowerChangeInt31ToCompressedSigned(Node* node); Node* LowerChangeInt31ToTaggedSigned(Node* node); Node* LowerChangeInt32ToTagged(Node* node); Node* LowerChangeInt64ToTagged(Node* node); @@ -221,6 +222,7 @@ class EffectControlLinearizer { Node* LowerStringComparison(Callable const& callable, Node* node); Node* IsElementsKindGreaterThan(Node* kind, ElementsKind reference_kind); + Node* ChangeInt32ToCompressedSmi(Node* value); Node* ChangeInt32ToSmi(Node* value); Node* ChangeInt32ToIntPtr(Node* value); Node* ChangeInt64ToSmi(Node* value); @@ -835,6 +837,9 @@ bool EffectControlLinearizer::TryWireInStateEffect(Node* node, case IrOpcode::kChangeBitToTagged: result = LowerChangeBitToTagged(node); break; + case IrOpcode::kChangeInt31ToCompressedSigned: + result = LowerChangeInt31ToCompressedSigned(node); + break; case IrOpcode::kChangeInt31ToTaggedSigned: result = LowerChangeInt31ToTaggedSigned(node); break; @@ -1386,6 +1391,11 @@ Node* EffectControlLinearizer::LowerChangeBitToTagged(Node* node) { return done.PhiAt(0); } +Node* EffectControlLinearizer::LowerChangeInt31ToCompressedSigned(Node* node) { + Node* value = node->InputAt(0); + return ChangeInt32ToCompressedSmi(value); +} + Node* EffectControlLinearizer::LowerChangeInt31ToTaggedSigned(Node* node) { Node* value = node->InputAt(0); return ChangeInt32ToSmi(value); @@ -4420,6 +4430,11 @@ Node* EffectControlLinearizer::ChangeIntPtrToInt32(Node* value) { return value; } +Node* EffectControlLinearizer::ChangeInt32ToCompressedSmi(Node* value) { + CHECK(machine()->Is64() && SmiValuesAre31Bits()); + return __ Word32Shl(value, SmiShiftBitsConstant()); +} + Node* EffectControlLinearizer::ChangeInt32ToSmi(Node* value) { // Do shift on 32bit values if Smis are stored in the lower word. if (machine()->Is64() && SmiValuesAre31Bits()) { diff --git a/src/compiler/opcodes.h b/src/compiler/opcodes.h index 986bce9281..0a0d310386 100644 --- a/src/compiler/opcodes.h +++ b/src/compiler/opcodes.h @@ -242,6 +242,7 @@ V(ChangeTaggedToTaggedSigned) \ V(ChangeCompressedToTaggedSigned) \ V(ChangeTaggedToCompressedSigned) \ + V(ChangeInt31ToCompressedSigned) \ V(ChangeInt31ToTaggedSigned) \ V(ChangeInt32ToTagged) \ V(ChangeInt64ToTagged) \ diff --git a/src/compiler/representation-change.cc b/src/compiler/representation-change.cc index 1aaa88db62..7f8c1719e4 100644 --- a/src/compiler/representation-change.cc +++ b/src/compiler/representation-change.cc @@ -634,9 +634,13 @@ Node* RepresentationChanger::GetCompressedSignedRepresentationFor( use_node, use_info); op = machine()->ChangeTaggedSignedToCompressedSigned(); } else if (IsWord(output_rep)) { - node = GetTaggedSignedRepresentationFor(node, output_rep, output_type, - use_node, use_info); - op = machine()->ChangeTaggedSignedToCompressedSigned(); + if (output_type.Is(Type::Signed31())) { + op = simplified()->ChangeInt31ToCompressedSigned(); + } else { + node = GetTaggedSignedRepresentationFor(node, output_rep, output_type, + use_node, use_info); + op = machine()->ChangeTaggedSignedToCompressedSigned(); + } } else if (output_rep == MachineRepresentation::kWord64) { node = GetTaggedSignedRepresentationFor(node, output_rep, output_type, use_node, use_info); diff --git a/src/compiler/simplified-operator.cc b/src/compiler/simplified-operator.cc index b5adc0e91f..537d26e8b6 100644 --- a/src/compiler/simplified-operator.cc +++ b/src/compiler/simplified-operator.cc @@ -731,6 +731,7 @@ bool operator==(CheckMinusZeroParameters const& lhs, V(ChangeCompressedToTaggedSigned, Operator::kNoProperties, 1, 0) \ V(ChangeTaggedToCompressedSigned, Operator::kNoProperties, 1, 0) \ V(ChangeFloat64ToTaggedPointer, Operator::kNoProperties, 1, 0) \ + V(ChangeInt31ToCompressedSigned, Operator::kNoProperties, 1, 0) \ V(ChangeInt31ToTaggedSigned, Operator::kNoProperties, 1, 0) \ V(ChangeInt32ToTagged, Operator::kNoProperties, 1, 0) \ V(ChangeInt64ToTagged, Operator::kNoProperties, 1, 0) \ diff --git a/src/compiler/simplified-operator.h b/src/compiler/simplified-operator.h index 60b367a197..19531b5b42 100644 --- a/src/compiler/simplified-operator.h +++ b/src/compiler/simplified-operator.h @@ -705,6 +705,7 @@ class V8_EXPORT_PRIVATE SimplifiedOperatorBuilder final const Operator* ChangeTaggedToTaggedSigned(); const Operator* ChangeCompressedToTaggedSigned(); const Operator* ChangeTaggedToCompressedSigned(); + const Operator* ChangeInt31ToCompressedSigned(); const Operator* ChangeInt31ToTaggedSigned(); const Operator* ChangeInt32ToTagged(); const Operator* ChangeInt64ToTagged(); diff --git a/src/compiler/verifier.cc b/src/compiler/verifier.cc index 51b5616487..32abf21d93 100644 --- a/src/compiler/verifier.cc +++ b/src/compiler/verifier.cc @@ -1375,6 +1375,7 @@ void Verifier::Visitor::Check(Node* node, const AllNodes& all) { // CheckTypeIs(node, to)); break; } + case IrOpcode::kChangeInt31ToCompressedSigned: case IrOpcode::kChangeInt31ToTaggedSigned: { // Signed31 /\ UntaggedInt32 -> Signed31 /\ Tagged // TODO(neis): Activate once ChangeRepresentation works in typer. diff --git a/test/cctest/compiler/test-representation-change.cc b/test/cctest/compiler/test-representation-change.cc index 5bd3df4deb..b4e26e7016 100644 --- a/test/cctest/compiler/test-representation-change.cc +++ b/test/cctest/compiler/test-representation-change.cc @@ -522,6 +522,9 @@ TEST(SingleChanges) { CheckChange(IrOpcode::kChangeBitToTagged, MachineRepresentation::kBit, Type::Boolean(), MachineRepresentation::kTagged); + CheckChange(IrOpcode::kChangeInt31ToCompressedSigned, + MachineRepresentation::kWord32, Type::Signed31(), + MachineRepresentation::kCompressedSigned); CheckChange(IrOpcode::kChangeInt31ToTaggedSigned, MachineRepresentation::kWord32, Type::Signed31(), MachineRepresentation::kTagged);