Commit d6b65658 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[ptr-compr] Add CheckedInt32ToCompressedSigned and use it

Also add tests for it.

Drive-by fix: Use ChangeInt32ToCompressedSmi since we have it

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: I45f04f8857acfc57b69eb4022a24ba082d28a91f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1708480Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62871}
parent dabbe5ee
......@@ -88,6 +88,7 @@ class EffectControlLinearizer {
Node* LowerCheckedUint32Div(Node* node, Node* frame_state);
Node* LowerCheckedUint32Mod(Node* node, Node* frame_state);
Node* LowerCheckedInt32Mul(Node* node, Node* frame_state);
Node* LowerCheckedInt32ToCompressedSigned(Node* node, Node* frame_state);
Node* LowerCheckedInt32ToTaggedSigned(Node* node, Node* frame_state);
Node* LowerCheckedInt64ToInt32(Node* node, Node* frame_state);
Node* LowerCheckedInt64ToTaggedSigned(Node* node, Node* frame_state);
......@@ -960,6 +961,9 @@ bool EffectControlLinearizer::TryWireInStateEffect(Node* node,
case IrOpcode::kCheckedInt32Mul:
result = LowerCheckedInt32Mul(node, frame_state);
break;
case IrOpcode::kCheckedInt32ToCompressedSigned:
result = LowerCheckedInt32ToCompressedSigned(node, frame_state);
break;
case IrOpcode::kCheckedInt32ToTaggedSigned:
result = LowerCheckedInt32ToTaggedSigned(node, frame_state);
break;
......@@ -1737,8 +1741,7 @@ Node* EffectControlLinearizer::LowerChangeTaggedToCompressedSigned(Node* node) {
STATIC_ASSERT(HeapNumber::kValueOffset == Oddball::kToNumberRawOffset);
Node* vfalse = __ LoadField(AccessBuilder::ForHeapNumberValue(), value);
vfalse = __ ChangeFloat64ToInt32(vfalse);
vfalse = ChangeInt32ToSmi(vfalse);
vfalse = __ ChangeTaggedSignedToCompressedSigned(vfalse);
vfalse = ChangeInt32ToCompressedSmi(vfalse);
__ Goto(&done, vfalse);
__ Bind(&done);
......@@ -2336,6 +2339,19 @@ Node* EffectControlLinearizer::LowerCheckedInt32Mul(Node* node,
return value;
}
Node* EffectControlLinearizer::LowerCheckedInt32ToCompressedSigned(
Node* node, Node* frame_state) {
DCHECK(SmiValuesAre31Bits());
Node* value = node->InputAt(0);
const CheckParameters& params = CheckParametersOf(node->op());
Node* add = __ Int32AddWithOverflow(value, value);
Node* check = __ Projection(1, add);
__ DeoptimizeIf(DeoptimizeReason::kLostPrecision, params.feedback(), check,
frame_state);
return __ Projection(0, add);
}
Node* EffectControlLinearizer::LowerCheckedInt32ToTaggedSigned(
Node* node, Node* frame_state) {
DCHECK(SmiValuesAre31Bits());
......
......@@ -267,6 +267,7 @@
V(CheckedUint32Div) \
V(CheckedUint32Mod) \
V(CheckedInt32Mul) \
V(CheckedInt32ToCompressedSigned) \
V(CheckedInt32ToTaggedSigned) \
V(CheckedInt64ToInt32) \
V(CheckedInt64ToTaggedSigned) \
......
......@@ -150,6 +150,7 @@ bool CheckSubsumes(Node const* a, Node const* b) {
case IrOpcode::kCheckNumber:
case IrOpcode::kCheckBigInt:
break;
case IrOpcode::kCheckedInt32ToCompressedSigned:
case IrOpcode::kCheckedInt32ToTaggedSigned:
case IrOpcode::kCheckedInt64ToInt32:
case IrOpcode::kCheckedInt64ToTaggedSigned:
......
......@@ -654,6 +654,13 @@ Node* RepresentationChanger::GetCompressedSignedRepresentationFor(
} else if (IsWord(output_rep)) {
if (output_type.Is(Type::Signed31())) {
op = simplified()->ChangeInt31ToCompressedSigned();
} else if (output_type.Is(Type::Signed32())) {
if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
op = simplified()->CheckedInt32ToCompressedSigned(use_info.feedback());
} else {
return TypeError(node, output_rep, output_type,
MachineRepresentation::kCompressedSigned);
}
} else {
node = GetTaggedSignedRepresentationFor(node, output_rep, output_type,
use_node, use_info);
......
......@@ -817,6 +817,7 @@ bool operator==(CheckMinusZeroParameters const& lhs,
V(CheckSmi, 1, 1) \
V(CheckString, 1, 1) \
V(CheckBigInt, 1, 1) \
V(CheckedInt32ToCompressedSigned, 1, 1) \
V(CheckedInt32ToTaggedSigned, 1, 1) \
V(CheckedInt64ToInt32, 1, 1) \
V(CheckedInt64ToTaggedSigned, 1, 1) \
......
......@@ -757,6 +757,8 @@ class V8_EXPORT_PRIVATE SimplifiedOperatorBuilder final
const Operator* CheckedInt32Mod();
const Operator* CheckedInt32Mul(CheckForMinusZeroMode);
const Operator* CheckedInt32Sub();
const Operator* CheckedInt32ToCompressedSigned(
const VectorSlotPair& feedback);
const Operator* CheckedInt32ToTaggedSigned(const VectorSlotPair& feedback);
const Operator* CheckedInt64ToInt32(const VectorSlotPair& feedback);
const Operator* CheckedInt64ToTaggedSigned(const VectorSlotPair& feedback);
......
......@@ -1534,6 +1534,7 @@ void Verifier::Visitor::Check(Node* node, const AllNodes& all) {
case IrOpcode::kCheckedUint32Div:
case IrOpcode::kCheckedUint32Mod:
case IrOpcode::kCheckedInt32Mul:
case IrOpcode::kCheckedInt32ToCompressedSigned:
case IrOpcode::kCheckedInt32ToTaggedSigned:
case IrOpcode::kCheckedInt64ToInt32:
case IrOpcode::kCheckedInt64ToTaggedSigned:
......
......@@ -299,6 +299,36 @@ TEST_F(RedundancyEliminationTest, CheckedFloat64ToInt64) {
}
}
// -----------------------------------------------------------------------------
// CheckedInt32ToCompressedSigned
TEST_F(RedundancyEliminationTest, CheckedInt32ToCompressedSigned) {
if (!COMPRESS_POINTERS_BOOL) {
return;
}
TRACED_FOREACH(VectorSlotPair, feedback1, vector_slot_pairs()) {
TRACED_FOREACH(VectorSlotPair, feedback2, vector_slot_pairs()) {
Node* value = Parameter(0);
Node* effect = graph()->start();
Node* control = graph()->start();
Node* check1 = effect = graph()->NewNode(
simplified()->CheckedInt32ToCompressedSigned(feedback1), value,
effect, control);
Reduction r1 = Reduce(check1);
ASSERT_TRUE(r1.Changed());
EXPECT_EQ(r1.replacement(), check1);
Node* check2 = effect = graph()->NewNode(
simplified()->CheckedInt32ToCompressedSigned(feedback2), value,
effect, control);
Reduction r2 = Reduce(check2);
ASSERT_TRUE(r2.Changed());
EXPECT_EQ(r2.replacement(), check1);
}
}
}
// -----------------------------------------------------------------------------
// CheckedInt32ToTaggedSigned
......
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