Index: src/hydrogen-instructions.cc |
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc |
index e362b95c60a81c0722e4a221e57ebd052271ada2..5cf4f8d62bc597ee77445545af7477d4930f3c04 100644 |
--- a/src/hydrogen-instructions.cc |
+++ b/src/hydrogen-instructions.cc |
@@ -1811,8 +1811,19 @@ Range* HMod::InferRange(Zone* zone) { |
if (representation().IsInteger32()) { |
Range* a = left()->range(); |
Range* b = right()->range(); |
- Range* result = new(zone) Range(); |
- if (a->CanBeMinusZero() || a->CanBeNegative()) { |
+ |
+ // The magnitude of the modulus is bounded by the right operand. |
Michael Starzinger
2013/05/29 11:59:54
A comment why we need to go through negtive-absolu
|
+ int32_t positive_bound = -Min(NegAbs(b->lower()), NegAbs(b->upper())) - 1; |
Michael Starzinger
2013/05/29 11:59:54
Not completely sure but isn't there a parenthesis
|
+ |
+ // The result of the modulo operation has the sign of its left operand. |
+ bool left_can_be_negative = a->CanBeMinusZero() || a->CanBeNegative(); |
+ Range* result = new(zone) Range(left_can_be_negative ? -positive_bound : 0, |
+ a->CanBePositive() ? positive_bound : 0); |
+ |
+ // The result is bounded by its left operand, too. |
+ result->Intersect(a); |
+ |
+ if (left_can_be_negative) { |
result->set_can_be_minus_zero(true); |
} |