Revision: 14884
Author: [email protected]
Date: Wed May 29 05:42:04 2013
Log: Improve range analysis for modulo operations.
[email protected]
Review URL: https://codereview.chromium.org/15952004
http://code.google.com/p/v8/source/detail?r=14884
Modified:
/branches/bleeding_edge/src/hydrogen-instructions.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
/branches/bleeding_edge/src/utils.h
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Wed May 29
03:47:55 2013
+++ /branches/bleeding_edge/src/hydrogen-instructions.cc Wed May 29
05:42:04 2013
@@ -1811,8 +1811,18 @@
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. 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 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);
+
+ if (left_can_be_negative) {
result->set_can_be_minus_zero(true);
}
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Wed May 29 03:47:55
2013
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Wed May 29 05:42:04
2013
@@ -263,6 +263,7 @@
bool CanBeMinusZero() const { return CanBeZero() && can_be_minus_zero_; }
bool CanBeZero() const { return upper_ >= 0 && lower_ <= 0; }
bool CanBeNegative() const { return lower_ < 0; }
+ bool CanBePositive() const { return upper_ > 0; }
bool Includes(int value) const { return lower_ <= value && upper_ >=
value; }
bool IsMostGeneric() const {
return lower_ == kMinInt && upper_ == kMaxInt && CanBeMinusZero();
=======================================
--- /branches/bleeding_edge/src/utils.h Thu May 16 03:59:17 2013
+++ /branches/bleeding_edge/src/utils.h Wed May 29 05:42:04 2013
@@ -230,6 +230,13 @@
T Min(T a, T b) {
return a < b ? a : b;
}
+
+
+// Returns the negative absolute value of its argument.
+template <typename T>
+T NegAbs(T a) {
+ return a < 0 ? a : -a;
+}
inline int StrLength(const char* string) {
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.