[turbofan] simplify code combining reductions

Change-Id: Ic372c7b7b308650518d0ddf938c389cfb7c2ea07
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2137407
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67248}
This commit is contained in:
Tobias Tebbi 2020-04-20 18:47:52 +02:00 committed by Commit Bot
parent a8ec38d23d
commit 7f2e53a7d1
7 changed files with 45 additions and 78 deletions

View File

@ -307,8 +307,7 @@ Reduction CommonOperatorReducer::ReduceReturn(Node* node) {
// hence checkpoints can be cut out of the effect chain flowing into it.
effect = NodeProperties::GetEffectInput(effect);
NodeProperties::ReplaceEffectInput(node, effect);
Reduction const reduction = ReduceReturn(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceReturn(node));
}
// TODO(ahaas): Extend the reduction below to multiple return values.
if (ValueInputCountOfReturn(node->op()) != 1) {

View File

@ -35,6 +35,10 @@ class Reduction final {
Node* replacement() const { return replacement_; }
bool Changed() const { return replacement() != nullptr; }
Reduction FollowedBy(Reduction next) const {
if (next.Changed()) return next;
return *this;
}
private:
Node* replacement_;

View File

@ -2419,8 +2419,7 @@ Reduction JSCallReducer::ReduceFunctionPrototypeApply(Node* node) {
node, javascript()->CallWithArrayLike(
p.frequency(), p.feedback(), p.speculation_mode(),
CallFeedbackRelation::kUnrelated));
Reduction const reduction = ReduceJSCallWithArrayLike(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCallWithArrayLike(node));
} else {
// Check whether {arguments_list} is null.
Node* check_null =
@ -2498,8 +2497,7 @@ Reduction JSCallReducer::ReduceFunctionPrototypeApply(Node* node) {
p.speculation_mode(),
CallFeedbackRelation::kUnrelated));
// Try to further reduce the JSCall {node}.
Reduction const reduction = ReduceJSCall(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCall(node));
}
// ES section #sec-function.prototype.bind
@ -2685,8 +2683,7 @@ Reduction JSCallReducer::ReduceFunctionPrototypeCall(Node* node) {
p.speculation_mode(),
CallFeedbackRelation::kUnrelated));
// Try to further reduce the JSCall {node}.
Reduction const reduction = ReduceJSCall(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCall(node));
}
// ES6 section 19.2.3.6 Function.prototype [ @@hasInstance ] (V)
@ -2918,8 +2915,7 @@ Reduction JSCallReducer::ReduceReflectApply(Node* node) {
node, javascript()->CallWithArrayLike(p.frequency(), p.feedback(),
p.speculation_mode(),
CallFeedbackRelation::kUnrelated));
Reduction const reduction = ReduceJSCallWithArrayLike(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCallWithArrayLike(node));
}
// ES6 section 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
@ -2942,8 +2938,7 @@ Reduction JSCallReducer::ReduceReflectConstruct(Node* node) {
}
NodeProperties::ChangeOp(node,
javascript()->ConstructWithArrayLike(p.frequency()));
Reduction const reduction = ReduceJSConstructWithArrayLike(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSConstructWithArrayLike(node));
}
// ES6 section 26.1.7 Reflect.getPrototypeOf ( target )
@ -3766,8 +3761,7 @@ Reduction JSCallReducer::ReduceCallOrConstructWithArrayLikeOrSpread(
node, javascript()->Call(arity + 1, frequency, feedback,
ConvertReceiverMode::kAny, speculation_mode,
CallFeedbackRelation::kUnrelated));
Reduction const reduction = ReduceJSCall(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCall(node));
} else {
NodeProperties::ChangeOp(
node, javascript()->Construct(arity + 2, frequency, feedback));
@ -3821,8 +3815,7 @@ Reduction JSCallReducer::ReduceCallOrConstructWithArrayLikeOrSpread(
graph()->NewNode(common()->Throw(), check_throw, check_fail);
NodeProperties::MergeControlToEnd(graph(), common(), throw_node);
Reduction const reduction = ReduceJSConstruct(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSConstruct(node));
}
}
@ -3911,8 +3904,7 @@ Reduction JSCallReducer::ReduceJSCall(Node* node) {
CallFeedbackRelation::kUnrelated));
// Try to further reduce the JSCall {node}.
Reduction const reduction = ReduceJSCall(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCall(node));
}
// Don't mess with other {node}s that have a constant {target}.
@ -3965,8 +3957,7 @@ Reduction JSCallReducer::ReduceJSCall(Node* node) {
CallFeedbackRelation::kUnrelated));
// Try to further reduce the JSCall {node}.
Reduction const reduction = ReduceJSCall(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCall(node));
}
if (!ShouldUseCallICFeedback(target) ||
@ -3998,8 +3989,7 @@ Reduction JSCallReducer::ReduceJSCall(Node* node) {
NodeProperties::ReplaceEffectInput(node, effect);
// Try to further reduce the JSCall {node}.
Reduction const reduction = ReduceJSCall(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCall(node));
} else if (feedback_target.has_value() && feedback_target->IsFeedbackCell()) {
FeedbackCellRef feedback_cell(
broker(), feedback_target.value().AsFeedbackCell().object());
@ -4022,8 +4012,7 @@ Reduction JSCallReducer::ReduceJSCall(Node* node) {
NodeProperties::ReplaceEffectInput(node, effect);
// Try to further reduce the JSCall {node}.
Reduction const reduction = ReduceJSCall(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSCall(node));
}
}
return NoChange();
@ -4475,8 +4464,7 @@ Reduction JSCallReducer::ReduceJSConstruct(Node* node) {
}
// Try to further reduce the JSConstruct {node}.
Reduction const reduction = ReduceJSConstruct(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSConstruct(node));
}
}
@ -4594,8 +4582,7 @@ Reduction JSCallReducer::ReduceJSConstruct(Node* node) {
javascript()->Construct(arity + 2, p.frequency(), FeedbackSource()));
// Try to further reduce the JSConstruct {node}.
Reduction const reduction = ReduceJSConstruct(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSConstruct(node));
}
// TODO(bmeurer): Also support optimizing proxies here.
@ -4635,8 +4622,7 @@ Reduction JSCallReducer::ReduceJSConstruct(Node* node) {
javascript()->Construct(arity + 2, p.frequency(), FeedbackSource()));
// Try to further reduce the JSConstruct {node}.
Reduction const reduction = ReduceJSConstruct(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSConstruct(node));
}
return NoChange();
@ -6233,8 +6219,7 @@ Reduction JSCallReducer::ReducePromisePrototypeCatch(Node* node) {
ConvertReceiverMode::kNotNullOrUndefined,
p.speculation_mode(),
CallFeedbackRelation::kUnrelated));
Reduction const reduction = ReducePromisePrototypeThen(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReducePromisePrototypeThen(node));
}
Node* JSCallReducer::CreateClosureFromBuiltinSharedFunctionInfo(
@ -6361,8 +6346,7 @@ Reduction JSCallReducer::ReducePromisePrototypeFinally(Node* node) {
ConvertReceiverMode::kNotNullOrUndefined,
p.speculation_mode(),
CallFeedbackRelation::kUnrelated));
Reduction const reduction = ReducePromisePrototypeThen(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReducePromisePrototypeThen(node));
}
Reduction JSCallReducer::ReducePromisePrototypeThen(Node* node) {

View File

@ -442,8 +442,7 @@ Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) {
NodeProperties::ReplaceValueInput(node, object, 1);
NodeProperties::ReplaceEffectInput(node, effect);
NodeProperties::ChangeOp(node, javascript()->OrdinaryHasInstance());
Reduction const reduction = ReduceJSOrdinaryHasInstance(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSOrdinaryHasInstance(node));
}
if (access_info.IsDataConstant()) {
@ -623,8 +622,7 @@ Reduction JSNativeContextSpecialization::ReduceJSOrdinaryHasInstance(
NodeProperties::ReplaceValueInput(
node, jsgraph()->Constant(bound_target_function), 1);
NodeProperties::ChangeOp(node, javascript()->InstanceOf(FeedbackSource()));
Reduction const reduction = ReduceJSInstanceOf(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSInstanceOf(node));
}
if (m.Ref(broker()).IsJSFunction()) {
@ -650,8 +648,7 @@ Reduction JSNativeContextSpecialization::ReduceJSOrdinaryHasInstance(
NodeProperties::ReplaceValueInput(node, object, 0);
NodeProperties::ReplaceValueInput(node, prototype_constant, 1);
NodeProperties::ChangeOp(node, javascript()->HasInPrototypeChain());
Reduction const reduction = ReduceJSHasInPrototypeChain(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSHasInPrototypeChain(node));
}
return NoChange();

View File

@ -540,16 +540,14 @@ Reduction JSTypedLowering::ReduceJSAdd(Node* node) {
NodeProperties::ChangeOp(node, javascript()->ToString());
NodeProperties::SetType(
node, Type::Intersect(r.type(), Type::String(), graph()->zone()));
Reduction const reduction = ReduceJSToString(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSToString(node));
} else if (r.RightInputIs(empty_string_type_)) {
// JSAdd(x:primitive, "") => JSToString(x)
NodeProperties::ReplaceValueInputs(node, r.left());
NodeProperties::ChangeOp(node, javascript()->ToString());
NodeProperties::SetType(
node, Type::Intersect(r.type(), Type::String(), graph()->zone()));
Reduction const reduction = ReduceJSToString(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSToString(node));
}
}
@ -1009,8 +1007,7 @@ Reduction JSTypedLowering::ReduceJSToNumeric(Node* node) {
if (input_type.Is(Type::NonBigIntPrimitive())) {
// ToNumeric(x:primitive\bigint) => ToNumber(x)
NodeProperties::ChangeOp(node, javascript()->ToNumber());
Reduction const reduction = ReduceJSToNumber(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceJSToNumber(node));
}
return NoChange();
}

View File

@ -361,8 +361,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
node->ReplaceInput(
1, Int32Constant(base::bits::WhichPowerOfTwo(m.right().Value())));
NodeProperties::ChangeOp(node, machine()->Word32Shl());
Reduction reduction = ReduceWord32Shl(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceWord32Shl(node));
}
break;
}
@ -879,8 +878,7 @@ Reduction MachineOperatorReducer::ReduceInt32Add(Node* node) {
node->ReplaceInput(0, m.right().node());
node->ReplaceInput(1, mleft.right().node());
NodeProperties::ChangeOp(node, machine()->Int32Sub());
Reduction const reduction = ReduceInt32Sub(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceInt32Sub(node));
}
}
if (m.right().IsInt32Sub()) {
@ -888,8 +886,7 @@ Reduction MachineOperatorReducer::ReduceInt32Add(Node* node) {
if (mright.left().Is(0)) { // y + (0 - x) => y - x
node->ReplaceInput(1, mright.right().node());
NodeProperties::ChangeOp(node, machine()->Int32Sub());
Reduction const reduction = ReduceInt32Sub(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceInt32Sub(node));
}
}
// (x + Int32Constant(a)) + Int32Constant(b)) => x + Int32Constant(a + b)
@ -940,8 +937,7 @@ Reduction MachineOperatorReducer::ReduceInt32Sub(Node* node) {
node->ReplaceInput(
1, Int32Constant(base::NegateWithWraparound(m.right().Value())));
NodeProperties::ChangeOp(node, machine()->Int32Add());
Reduction const reduction = ReduceInt32Add(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceInt32Add(node));
}
return NoChange();
}
@ -959,8 +955,7 @@ Reduction MachineOperatorReducer::ReduceInt64Sub(Node* node) {
node->ReplaceInput(
1, Int64Constant(base::NegateWithWraparound(m.right().Value())));
NodeProperties::ChangeOp(node, machine()->Int64Add());
Reduction const reduction = ReduceInt64Add(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceInt64Add(node));
}
return NoChange();
}
@ -984,8 +979,7 @@ Reduction MachineOperatorReducer::ReduceInt64Mul(Node* node) {
node->ReplaceInput(
1, Int64Constant(base::bits::WhichPowerOfTwo(m.right().Value())));
NodeProperties::ChangeOp(node, machine()->Word64Shl());
Reduction reduction = ReduceWord64Shl(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceWord64Shl(node));
}
return NoChange();
}
@ -1268,8 +1262,7 @@ Reduction MachineOperatorReducer::ReduceWord32Shl(Node* node) {
node->ReplaceInput(1,
Uint32Constant(~((1U << m.right().Value()) - 1U)));
NodeProperties::ChangeOp(node, machine()->Word32And());
Reduction reduction = ReduceWord32And(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceWord32And(node));
}
}
}
@ -1331,8 +1324,7 @@ Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) {
node->ReplaceInput(0, Int32Constant(0));
node->ReplaceInput(1, mleft.left().node());
NodeProperties::ChangeOp(node, machine()->Int32Sub());
Reduction const reduction = ReduceInt32Sub(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(ReduceInt32Sub(node));
}
} else if (mleft.left().IsLoad()) {
LoadRepresentation const rep =
@ -1382,8 +1374,7 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
node->ReplaceInput(0, mleft.left().node());
node->ReplaceInput(
1, a.IntNConstant(m.right().Value() & mleft.right().Value()));
Reduction const reduction = a.ReduceWordNAnd(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(a.ReduceWordNAnd(node));
}
}
if (m.right().IsNegativePowerOf2()) {
@ -1406,8 +1397,7 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
a.WordNAnd(mleft.left().node(), m.right().node()));
node->ReplaceInput(1, mleft.right().node());
NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
Reduction const reduction = a.ReduceIntNAdd(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
}
if (A::IsIntNMul(mleft.left())) {
typename A::IntNBinopMatcher mleftleft(mleft.left().node());
@ -1417,8 +1407,7 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
0, a.WordNAnd(mleft.right().node(), m.right().node()));
node->ReplaceInput(1, mleftleft.node());
NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
Reduction const reduction = a.ReduceIntNAdd(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
}
}
if (A::IsIntNMul(mleft.right())) {
@ -1429,8 +1418,7 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
a.WordNAnd(mleft.left().node(), m.right().node()));
node->ReplaceInput(1, mleftright.node());
NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
Reduction const reduction = a.ReduceIntNAdd(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
}
}
if (A::IsWordNShl(mleft.left())) {
@ -1441,8 +1429,7 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
0, a.WordNAnd(mleft.right().node(), m.right().node()));
node->ReplaceInput(1, mleftleft.node());
NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
Reduction const reduction = a.ReduceIntNAdd(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
}
}
if (A::IsWordNShl(mleft.right())) {
@ -1453,8 +1440,7 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
a.WordNAnd(mleft.left().node(), m.right().node()));
node->ReplaceInput(1, mleftright.node());
NodeProperties::ChangeOp(node, a.IntNAdd(machine()));
Reduction const reduction = a.ReduceIntNAdd(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(a.ReduceIntNAdd(node));
}
}
} else if (A::IsIntNMul(m.left())) {

View File

@ -333,8 +333,8 @@ Reduction RedundancyElimination::ReduceSpeculativeNumberComparison(Node* node) {
// the regular Number comparisons in JavaScript also identify
// 0 and -0 (unlike special comparisons as Object.is).
NodeProperties::ReplaceValueInput(node, check, 0);
Reduction const reduction = ReduceSpeculativeNumberComparison(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(
ReduceSpeculativeNumberComparison(node));
}
}
}
@ -351,8 +351,8 @@ Reduction RedundancyElimination::ReduceSpeculativeNumberComparison(Node* node) {
// the regular Number comparisons in JavaScript also identify
// 0 and -0 (unlike special comparisons as Object.is).
NodeProperties::ReplaceValueInput(node, check, 1);
Reduction const reduction = ReduceSpeculativeNumberComparison(node);
return reduction.Changed() ? reduction : Changed(node);
return Changed(node).FollowedBy(
ReduceSpeculativeNumberComparison(node));
}
}
}