Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Unified Diff: src/hydrogen.cc

Issue 14211009: Crankshaft: Recognize (i >>> 0) === i for integer32 inputs and replace (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698