Commit b0c7a0fc authored by neis's avatar neis Committed by Commit bot

[compiler] Refine typing of NumberShiftRightLogical.

Use the type of the RHS to compute a more precise output type.  In
particular, if the RHS is, say, 1, we now know that the result is a
subtype of Unsigned31.

R=jarin@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2706763003
Cr-Commit-Position: refs/heads/master@{#43340}
parent 99d61819
......@@ -864,12 +864,29 @@ Type* OperationTyper::NumberShiftRightLogical(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited()) return Type::None();
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None();
lhs = NumberToUint32(lhs);
rhs = NumberToUint32(rhs);
uint32_t min_lhs = lhs->Min();
uint32_t max_lhs = lhs->Max();
uint32_t min_rhs = rhs->Min();
uint32_t max_rhs = rhs->Max();
if (max_rhs > 31) {
// rhs can be larger than the bitmask
max_rhs = 31;
min_rhs = 0;
}
double min = min_lhs >> max_rhs;
double max = max_lhs >> min_rhs;
DCHECK_LE(0, min);
DCHECK_LE(max, kMaxUInt32);
// Logical right-shifting any value cannot make it larger.
return Type::Range(0.0, lhs->Max(), zone());
if (min == 0 && max == kMaxInt) return Type::Unsigned31();
if (min == 0 && max == kMaxUInt32) return Type::Unsigned32();
return Type::Range(min, max, zone());
}
Type* OperationTyper::NumberAtan2(Type* lhs, Type* rhs) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment