Revision: 14996
Author: [email protected]
Date: Fri Jun 7 02:07:53 2013
Log: Infer the range of Math.abs
[email protected], [email protected]
Review URL: https://chromiumcodereview.appspot.com/16268009
http://code.google.com/p/v8/source/detail?r=14996
Modified:
/branches/bleeding_edge/src/hydrogen-instructions.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Wed Jun 5
10:24:14 2013
+++ /branches/bleeding_edge/src/hydrogen-instructions.cc Fri Jun 7
02:07:53 2013
@@ -1306,6 +1306,30 @@
return NULL;
}
}
+
+
+Range* HUnaryMathOperation::InferRange(Zone* zone) {
+ Representation r = representation();
+ if (r.IsSmiOrInteger32() && value()->HasRange()) {
+ if (op() == kMathAbs) {
+ int upper = value()->range()->upper();
+ int lower = value()->range()->lower();
+ bool spans_zero = value()->range()->CanBeZero();
+ // Math.abs(kMinInt) overflows its representation, on which the
+ // instruction deopts. Hence clamp it to kMaxInt.
+ int abs_upper = upper == kMinInt ? kMaxInt : abs(upper);
+ int abs_lower = lower == kMinInt ? kMaxInt : abs(lower);
+ Range* result =
+ new(zone) Range(spans_zero ? 0 : Min(abs_lower, abs_upper),
+ Max(abs_lower, abs_upper));
+ // In case of Smi representation, clamp Math.abs(Smi::kMinValue) to
+ // Smi::kMaxValue.
+ if (r.IsSmi()) result->ClampToSmi();
+ return result;
+ }
+ }
+ return HValue::InferRange(zone);
+}
void HUnaryMathOperation::PrintDataTo(StringStream* stream) {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Wed Jun 5 03:43:18
2013
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Fri Jun 7 02:07:53
2013
@@ -271,6 +271,10 @@
bool IsInSmiRange() const {
return lower_ >= Smi::kMinValue && upper_ <= Smi::kMaxValue;
}
+ void ClampToSmi() {
+ lower_ = Max(lower_, Smi::kMinValue);
+ upper_ = Min(upper_, Smi::kMaxValue);
+ }
void KeepOrder();
#ifdef DEBUG
void Verify() const;
@@ -2643,6 +2647,8 @@
}
}
}
+
+ virtual Range* InferRange(Zone* zone);
virtual HValue* Canonicalize();
--
--
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.