Index: src/compiler/js-intrinsic-lowering.cc |
diff --git a/src/compiler/js-intrinsic-lowering.cc b/src/compiler/js-intrinsic-lowering.cc |
index ca5cb932b4bd7606521b32ae63c7c8076779d74f..2d5c0c77a7e64b8705a80ee43c87b946edc61af0 100644 |
--- a/src/compiler/js-intrinsic-lowering.cc |
+++ b/src/compiler/js-intrinsic-lowering.cc |
@@ -507,12 +507,43 @@ Reduction JSIntrinsicLowering::ReduceSubString(Node* node) { |
Reduction JSIntrinsicLowering::ReduceToInteger(Node* node) { |
Node* value = NodeProperties::GetValueInput(node, 0); |
+ Node* context = NodeProperties::GetContextInput(node); |
+ Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); |
+ Node* effect = NodeProperties::GetEffectInput(node); |
+ Node* control = NodeProperties::GetControlInput(node); |
+ |
+ // ToInteger is a no-op on integer values and -0. |
Type* value_type = NodeProperties::GetType(value); |
if (value_type->Is(type_cache().kIntegerOrMinusZero)) { |
ReplaceWithValue(node, value); |
return Replace(value); |
} |
- return NoChange(); |
+ |
+ Node* check = graph()->NewNode(simplified()->ObjectIsSmi(), value); |
+ Node* branch = |
+ graph()->NewNode(common()->Branch(BranchHint::kTrue), check, control); |
+ |
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
+ Node* etrue = effect; |
+ Node* vtrue = value; |
+ |
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
+ Node* efalse = effect; |
+ Node* vfalse; |
+ { |
+ vfalse = efalse = |
+ graph()->NewNode(javascript()->CallRuntime(Runtime::kToInteger), value, |
+ context, frame_state, efalse, if_false); |
+ if_false = graph()->NewNode(common()->IfSuccess(), vfalse); |
+ } |
+ |
+ control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
+ effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); |
+ value = graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2), |
+ vtrue, vfalse, control); |
+ // TODO(bmeurer, mstarzinger): Rewire IfException inputs to {vfalse}. |
+ ReplaceWithValue(node, value, effect, control); |
+ return Changed(value); |
} |