Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Unified Diff: src/hydrogen-instructions.cc

Issue 15952004: Improve range analysis for modulo operations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698