Commit c91c3961 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Do strength reduction for ObjectIsSmi based on inputs.

Ideally we would have a dedicated MachineRepresentation for Smis during
representation selection and use that to properly optimize ObjectIsSmi
(and other ObjectIs<Type> predicates), but that will take some time to
get that done. So in the meantime we can just do simple (local) strength
reduction on ObjectIsSmi to avoid Smi checks in the simplest cases at
least.

R=jarin@chromium.org

Review-Url: https://codereview.chromium.org/2047213002
Cr-Commit-Position: refs/heads/master@{#36809}
parent 80b98da2
......@@ -110,6 +110,14 @@ Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
}
break;
}
case IrOpcode::kObjectIsSmi: {
NumberMatcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceBoolean(IsSmiDouble(m.Value()));
if (m.IsChangeBitToTagged()) return ReplaceBoolean(false);
if (m.IsChangeInt31ToTaggedSigned()) return ReplaceBoolean(true);
if (m.IsHeapConstant()) return ReplaceBoolean(false);
break;
}
case IrOpcode::kNumberCeil:
case IrOpcode::kNumberFloor:
case IrOpcode::kNumberRound:
......@@ -165,6 +173,9 @@ Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op,
return Changed(node);
}
Reduction SimplifiedOperatorReducer::ReplaceBoolean(bool value) {
return Replace(jsgraph()->BooleanConstant(value));
}
Reduction SimplifiedOperatorReducer::ReplaceFloat64(double value) {
return Replace(jsgraph()->Float64Constant(value));
......
......@@ -33,6 +33,7 @@ class SimplifiedOperatorReducer final : public Reducer {
Reduction ReduceTypeGuard(Node* node);
Reduction Change(Node* node, const Operator* op, Node* a);
Reduction ReplaceBoolean(bool value);
Reduction ReplaceFloat64(double value);
Reduction ReplaceInt32(int32_t value);
Reduction ReplaceUint32(uint32_t value) {
......
......@@ -48,6 +48,9 @@ class GraphTest : public TestWithContext, public TestWithIsolateAndZone {
Node* EmptyFrameState();
Matcher<Node*> IsBooleanConstant(bool value) {
return value ? IsTrueConstant() : IsFalseConstant();
}
Matcher<Node*> IsFalseConstant();
Matcher<Node*> IsTrueConstant();
Matcher<Node*> IsUndefinedConstant();
......
......@@ -342,6 +342,49 @@ TEST_F(SimplifiedOperatorReducerTest, TruncateTaggedToWord32WithConstant) {
}
}
// -----------------------------------------------------------------------------
// TruncateTaggedToWord32
TEST_F(SimplifiedOperatorReducerTest, ObjectIsSmiWithChangeBitToTagged) {
Node* param0 = Parameter(0);
Reduction reduction = Reduce(graph()->NewNode(
simplified()->ObjectIsSmi(),
graph()->NewNode(simplified()->ChangeBitToTagged(), param0)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFalseConstant());
}
TEST_F(SimplifiedOperatorReducerTest,
ObjectIsSmiWithChangeInt31ToTaggedSigned) {
Node* param0 = Parameter(0);
Reduction reduction = Reduce(graph()->NewNode(
simplified()->ObjectIsSmi(),
graph()->NewNode(simplified()->ChangeInt31ToTaggedSigned(), param0)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsTrueConstant());
}
TEST_F(SimplifiedOperatorReducerTest, ObjectIsSmiWithHeapConstant) {
Handle<HeapObject> kHeapObjects[] = {
factory()->empty_string(), factory()->null_value(),
factory()->species_symbol(), factory()->undefined_value()};
TRACED_FOREACH(Handle<HeapObject>, o, kHeapObjects) {
Reduction reduction =
Reduce(graph()->NewNode(simplified()->ObjectIsSmi(), HeapConstant(o)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFalseConstant());
}
}
TEST_F(SimplifiedOperatorReducerTest, ObjectIsSmiWithNumberConstant) {
TRACED_FOREACH(double, n, kFloat64Values) {
Reduction reduction = Reduce(
graph()->NewNode(simplified()->ObjectIsSmi(), NumberConstant(n)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsBooleanConstant(IsSmiDouble(n)));
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
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