Commit 1f518684 authored by bmeurer's avatar bmeurer Committed by Commit bot

[crankshaft] Properly optimize strict equality with constants.

For values with canonical representation (i.e. not Number, Simd128Value
or Number) we can turn a strict equality comparison to a direct pointer
comparison. This removes the weird performance cliff when using a null
or undefined constant instead of the literals.

R=jarin@chromium.org
BUG=v8:5042

Review-Url: https://codereview.chromium.org/2027603002
Cr-Commit-Position: refs/heads/master@{#36612}
parent 7554360f
......@@ -11593,18 +11593,22 @@ void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr,
return ast_context()->ReturnControl(instr, expr->id());
}
namespace {
static bool IsLiteralCompareBool(Isolate* isolate,
HValue* left,
Token::Value op,
HValue* right) {
bool IsLiteralCompareStrict(Isolate* isolate, HValue* left, Token::Value op,
HValue* right) {
return op == Token::EQ_STRICT &&
((left->IsConstant() &&
HConstant::cast(left)->handle(isolate)->IsBoolean()) ||
(right->IsConstant() &&
HConstant::cast(right)->handle(isolate)->IsBoolean()));
((left->IsConstant() &&
!HConstant::cast(left)->handle(isolate)->IsNumber() &&
!HConstant::cast(left)->handle(isolate)->IsSimd128Value() &&
!HConstant::cast(left)->handle(isolate)->IsString()) ||
(right->IsConstant() &&
!HConstant::cast(right)->handle(isolate)->IsNumber() &&
!HConstant::cast(right)->handle(isolate)->IsSimd128Value() &&
!HConstant::cast(right)->handle(isolate)->IsString()));
}
} // namespace
void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
DCHECK(!HasStackOverflow());
......@@ -11650,7 +11654,7 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
HValue* left = Pop();
Token::Value op = expr->op();
if (IsLiteralCompareBool(isolate(), left, op, right)) {
if (IsLiteralCompareStrict(isolate(), left, op, right)) {
HCompareObjectEqAndBranch* result =
New<HCompareObjectEqAndBranch>(left, right);
return ast_context()->ReturnControl(result, expr->id());
......
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