Revision: 8735
Author: [email protected]
Date: Mon Jul 25 06:28:35 2011
Log: Better range information for logical shift right >>>.
If the input range is positive and the shift count is constant
we can replace >>> with >> to compute the output range.
For negative inputs, we can only compute a range if the
result always fits into a signed int32.
BUG=v8:1510
Review URL: http://codereview.chromium.org/7489043
http://code.google.com/p/v8/source/detail?r=8735
Modified:
/branches/bleeding_edge/src/hydrogen-instructions.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Wed Jul 20
07:43:10 2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.cc Mon Jul 25
06:28:35 2011
@@ -1228,6 +1228,30 @@
}
return HValue::InferRange();
}
+
+
+Range* HShr::InferRange() {
+ if (right()->IsConstant()) {
+ HConstant* c = HConstant::cast(right());
+ if (c->HasInteger32Value()) {
+ int shift_count = c->Integer32Value() & 0x1f;
+ if (left()->range()->CanBeNegative()) {
+ // Only compute bounds if the result always fits into an int32.
+ return (shift_count >= 1)
+ ? new Range(0, static_cast<uint32_t>(0xffffffff) >>
shift_count)
+ : new Range();
+ } else {
+ // For positive inputs we can use the >> operator.
+ Range* result = (left()->range() != NULL)
+ ? left()->range()->Copy()
+ : new Range();
+ result->Sar(c->Integer32Value());
+ return result;
+ }
+ }
+ }
+ return HValue::InferRange();
+}
Range* HShl::InferRange() {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Thu Jul 21 05:01:51
2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Mon Jul 25 06:28:35
2011
@@ -3060,6 +3060,7 @@
HShr(HValue* context, HValue* left, HValue* right)
: HBitwiseBinaryOperation(context, left, right) { }
+ virtual Range* InferRange();
virtual HType CalculateInferredType();
DECLARE_CONCRETE_INSTRUCTION(Shr)
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev