Commit 3861e513 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Properly optimize JSToBoolean with Number inputs.

For JSToBoolean with Number inputs we still called out to the
ToBooleanStub, even though we easily handle them inline nowadays.

R=jarin@chromium.org

Review-Url: https://codereview.chromium.org/2145923002
Cr-Commit-Position: refs/heads/master@{#37699}
parent dae6320d
......@@ -830,6 +830,14 @@ Reduction JSTypedLowering::ReduceJSToBoolean(Node* node) {
node->TrimInputCount(1);
NodeProperties::ChangeOp(node, simplified()->BooleanNot());
return Changed(node);
} else if (input_type->Is(Type::Number())) {
// JSToBoolean(x:number) => NumberLessThan(#0,NumberAbs(x))
RelaxEffectsAndControls(node);
node->ReplaceInput(0, jsgraph()->ZeroConstant());
node->ReplaceInput(1, graph()->NewNode(simplified()->NumberAbs(), input));
node->TrimInputCount(2);
NodeProperties::ChangeOp(node, simplified()->NumberLessThan());
return Changed(node);
} else if (input_type->Is(Type::String())) {
// JSToBoolean(x:string) => NumberLessThan(#0,x.length)
FieldAccess const access = AccessBuilder::ForStringLength();
......
......@@ -284,6 +284,15 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) {
IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0.0))));
}
TEST_F(JSTypedLoweringTest, JSToBooleanWithNumber) {
Node* input = Parameter(Type::Number(), 0);
Node* context = Parameter(Type::Any(), 1);
Reduction r = Reduce(graph()->NewNode(
javascript()->ToBoolean(ToBooleanHint::kAny), input, context));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsNumberLessThan(IsNumberConstant(0.0), IsNumberAbs(input)));
}
TEST_F(JSTypedLoweringTest, JSToBooleanWithString) {
Node* input = Parameter(Type::String(), 0);
......
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