Chromium Code Reviews| Index: src/hydrogen.cc |
| =================================================================== |
| --- src/hydrogen.cc (revision 14364) |
| +++ src/hydrogen.cc (working copy) |
| @@ -10041,6 +10041,21 @@ |
| } |
| +void HOptimizedGraphBuilder::HandleTripleShiftZeroCompare( |
| + CompareOperation* expr, |
| + HValue* input) { |
| + // (i >>> 0) === i is transformed to i >= 0. |
| + // (i >>> 0) !== i is transformed to i < 0. |
| + Token::Value op = (expr->op() == Token::EQ_STRICT) ? Token::GTE : Token::LT; |
| + HCompareIDAndBranch* compare = |
| + new(zone()) HCompareIDAndBranch(input, graph()->GetConstant0(), op); |
| + compare->set_observed_input_representation(Representation::Integer32(), |
|
Jakob Kummerow
2013/04/23 11:09:23
Manually setting observed input representations is
|
| + Representation::Integer32()); |
| + compare->set_position(expr->position()); |
| + return ast_context()->ReturnControl(compare, expr->id()); |
| +} |
| + |
| + |
| void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, |
| HTypeof* typeof_expr, |
| Handle<String> check) { |
| @@ -10067,6 +10082,34 @@ |
| } |
| +// Recognize the pattern (i >>> 0) !== i. |
| +static bool MatchTripleShiftZeroCompare(HValue* left, |
| + Token::Value op, |
| + HValue* right, |
| + HValue** input) { |
| + if (!right->representation().IsInteger32()) return false; |
|
Jakob Kummerow
2013/04/23 11:09:23
You can't rely on representations at graph constru
|
| + if (!left->IsShr()) return false; |
| + HShr* shr = HShr::cast(left); |
| + if (right != shr->left()) return false; |
| + if (!shr->right()->IsConstant()) return false; |
| + HConstant* shiftOperand = HConstant::cast(shr->right()); |
| + if (*(shiftOperand->handle()) != Smi::FromInt(0)) return false; |
| + *input = right; |
| + return true; |
| +} |
| + |
| + |
| +static bool IsTripleShiftZeroCompare(HValue* left, |
| + Token::Value op, |
| + HValue* right, |
| + HValue** input) { |
| + if (!Token::IsStrictOp(op)) return false; |
| + return MatchTripleShiftZeroCompare(left, op, right, input) || |
| + MatchTripleShiftZeroCompare(right, op, left, input); |
| +} |
| + |
| + |
| + |
| static bool MatchLiteralCompareTypeof(HValue* left, |
| Token::Value op, |
| HValue* right, |
| @@ -10156,6 +10199,9 @@ |
| return HandleLiteralCompareTypeof(expr, typeof_expr, check); |
| } |
| HValue* sub_expr = NULL; |
| + if (IsTripleShiftZeroCompare(left, op, right, &sub_expr)) { |
| + return HandleTripleShiftZeroCompare(expr, sub_expr); |
| + } |
| Factory* f = isolate()->factory(); |
| if (IsLiteralCompareNil(left, op, right, f->undefined_value(), &sub_expr)) { |
| return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue); |