Index: src/hydrogen-instructions.cc |
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc |
index 2cbf5040010acf1a9707ab52638312b5a6620aad..bea3cea9f68865657cac588f75a589eb6fed8029 100644 |
--- a/src/hydrogen-instructions.cc |
+++ b/src/hydrogen-instructions.cc |
@@ -1922,15 +1922,18 @@ Range* HMathFloorOfDiv::InferRange(Zone* zone) { |
} |
+// Returns the absolute value of its argument minus one, avoiding undefined |
+// behavior at kMinInt. |
+static int32_t AbsMinus1(int32_t a) { return a < 0 ? -(a + 1) : (a - 1); } |
+ |
+ |
Range* HMod::InferRange(Zone* zone) { |
if (representation().IsInteger32()) { |
Range* a = left()->range(); |
Range* b = right()->range(); |
- // The magnitude of the modulus is bounded by the right operand. Note that |
- // apart for the cases involving kMinInt, the calculation below is the same |
- // as Max(Abs(b->lower()), Abs(b->upper())) - 1. |
- int32_t positive_bound = -(Min(NegAbs(b->lower()), NegAbs(b->upper())) + 1); |
+ // The magnitude of the modulus is bounded by the right operand. |
+ int32_t positive_bound = Max(AbsMinus1(b->lower()), AbsMinus1(b->upper())); |
// The result of the modulo operation has the sign of its left operand. |
bool left_can_be_negative = a->CanBeMinusZero() || a->CanBeNegative(); |