Commit 99aaa69b authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Consume feedback types for NumberMax and NumberMin.

For nodes

  NumberMin(lhs, rhs)
  NumberMax(lhs, rhs)

we might have feedback types for lhs and rhs that would allow us to
generate unsigned32 or signed32 versions of this operator, which is way
more efficient that going to the full Float64Min/Float64Max operator.
However we cannot promise word32 truncations in this case, since we
based this decision on the feedback types.

This allows us to generate better code for Math.min and Math.max when
one of the inputs is a speculative number operator that provides better
typing during representation selection. We've seen such code in the
hottest function on Google Maps for example.

BUG=v8:5267
R=jarin@chromium.org,mvstanton@chromium.org

Review-Url: https://codereview.chromium.org/2734193003
Cr-Commit-Position: refs/heads/master@{#43660}
parent 76224f7e
......@@ -2061,20 +2061,27 @@ class RepresentationSelector {
return;
}
case IrOpcode::kNumberMax: {
// TODO(turbofan): We should consider feedback types here as well.
if (BothInputsAreUnsigned32(node)) {
// It is safe to use the feedback types for left and right hand side
// here, since we can only narrow those types and thus we can only
// promise a more specific truncation.
Type* const lhs_type = TypeOf(node->InputAt(0));
Type* const rhs_type = TypeOf(node->InputAt(1));
if (lhs_type->Is(Type::Unsigned32()) &&
rhs_type->Is(Type::Unsigned32())) {
VisitWord32TruncatingBinop(node);
if (lower()) {
lowering->DoMax(node, lowering->machine()->Uint32LessThan(),
MachineRepresentation::kWord32);
}
} else if (BothInputsAreSigned32(node)) {
} else if (lhs_type->Is(Type::Signed32()) &&
rhs_type->Is(Type::Signed32())) {
VisitWord32TruncatingBinop(node);
if (lower()) {
lowering->DoMax(node, lowering->machine()->Int32LessThan(),
MachineRepresentation::kWord32);
}
} else if (BothInputsAre(node, Type::PlainNumber())) {
} else if (lhs_type->Is(Type::PlainNumber()) &&
rhs_type->Is(Type::PlainNumber())) {
VisitFloat64Binop(node);
if (lower()) {
lowering->DoMax(node, lowering->machine()->Float64LessThan(),
......@@ -2087,20 +2094,27 @@ class RepresentationSelector {
return;
}
case IrOpcode::kNumberMin: {
// TODO(turbofan): We should consider feedback types here as well.
if (BothInputsAreUnsigned32(node)) {
// It is safe to use the feedback types for left and right hand side
// here, since we can only narrow those types and thus we can only
// promise a more specific truncation.
Type* const lhs_type = TypeOf(node->InputAt(0));
Type* const rhs_type = TypeOf(node->InputAt(1));
if (lhs_type->Is(Type::Unsigned32()) &&
rhs_type->Is(Type::Unsigned32())) {
VisitWord32TruncatingBinop(node);
if (lower()) {
lowering->DoMin(node, lowering->machine()->Uint32LessThan(),
MachineRepresentation::kWord32);
}
} else if (BothInputsAreSigned32(node)) {
} else if (lhs_type->Is(Type::Signed32()) &&
rhs_type->Is(Type::Signed32())) {
VisitWord32TruncatingBinop(node);
if (lower()) {
lowering->DoMin(node, lowering->machine()->Int32LessThan(),
MachineRepresentation::kWord32);
}
} else if (BothInputsAre(node, Type::PlainNumber())) {
} else if (lhs_type->Is(Type::PlainNumber()) &&
rhs_type->Is(Type::PlainNumber())) {
VisitFloat64Binop(node);
if (lower()) {
lowering->DoMin(node, lowering->machine()->Float64LessThan(),
......
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