Index: src/compiler/simplified-lowering.cc |
diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc |
index 0cc53ed9b48072796dcc8a44757edd3412ca4660..6fbd3130e6718a615394b1e47742af51b599f400 100644 |
--- a/src/compiler/simplified-lowering.cc |
+++ b/src/compiler/simplified-lowering.cc |
@@ -1077,6 +1077,10 @@ class RepresentationSelector { |
return jsgraph_->simplified(); |
} |
+ void ChangeToInt32MulWithOverflowOp(Node* node, CheckForMinusZeroMode kMode) { |
+ NodeProperties::ChangeOp(node, simplified()->CheckedInt32Mul(kMode)); |
+ } |
+ |
void ChangeToInt32OverflowOp(Node* node) { |
NodeProperties::ChangeOp(node, Int32OverflowOp(node)); |
} |
@@ -1334,6 +1338,22 @@ class RepresentationSelector { |
// Try to use type feedback. |
BinaryOperationHints::Hint hint = BinaryOperationHintOf(node->op()); |
+ // Determine if one of the inputs is a constant integer > 0. |
+ Type* input0_type = NodeProperties::GetType(node->InputAt(0)); |
+ Type* input1_type = NodeProperties::GetType(node->InputAt(1)); |
Jarin
2016/07/17 18:24:41
You can use TypeOf here (instead of NodeProperties
mvstanton
2016/07/18 08:48:58
Done.
|
+ bool positive_range = false; |
+ if ((input0_type->IsRange() && input0_type->AsRange()->Min() > 0) || |
+ (input1_type->IsRange() && input1_type->AsRange()->Min() > 0)) { |
Jarin
2016/07/17 16:37:47
Maybe it is better to not refer to ranges here and
Benedikt Meurer
2016/07/17 17:44:07
Yes, please. And I'd prefer to have this inline be
mvstanton
2016/07/18 08:48:58
No problemo
mvstanton
2016/07/18 08:48:58
Done.
|
+ positive_range = true; |
+ } |
+ |
+ // If one of the inputs is positive and/or truncation is being applied, |
+ // there is no need to return -0. |
+ CheckForMinusZeroMode mz_mode = |
+ (truncation.TruncatesToWord32() || positive_range) |
+ ? CheckForMinusZeroMode::kDontCheckForMinusZero |
+ : CheckForMinusZeroMode::kCheckForMinusZero; |
Jarin
2016/07/17 18:24:41
Looking at this again, this logic is only used whe
mvstanton
2016/07/18 08:48:58
Good idea, done!
|
+ |
// Handle the case when no int32 checks on inputs are necessary |
// (but an overflow check is needed on the output). |
if (BothInputsAre(node, Type::Signed32())) { |
@@ -1342,7 +1362,7 @@ class RepresentationSelector { |
hint == BinaryOperationHints::kSigned32) { |
VisitBinop(node, UseInfo::TruncatingWord32(), |
MachineRepresentation::kWord32, Type::Signed32()); |
- if (lower()) ChangeToInt32OverflowOp(node); |
+ if (lower()) ChangeToInt32MulWithOverflowOp(node, mz_mode); |
return; |
} |
} |
@@ -1351,7 +1371,7 @@ class RepresentationSelector { |
hint == BinaryOperationHints::kSigned32) { |
VisitBinop(node, UseInfo::CheckedSigned32AsWord32(), |
MachineRepresentation::kWord32, Type::Signed32()); |
- if (lower()) ChangeToInt32OverflowOp(node); |
+ if (lower()) ChangeToInt32MulWithOverflowOp(node, mz_mode); |
return; |
} |