Revision: 14306
Author: [email protected]
Date: Wed Apr 17 05:47:15 2013
Log: Improve handling of unary plus.
Simple strategy: Transform unary plus into multiplication by one directly
in the
parser and remove it from the Hydrogen graph later. This gives correct type
feedback without any special stub for it.
BUG=v8:2527
Review URL: https://codereview.chromium.org/13902013
http://code.google.com/p/v8/source/detail?r=14306
Modified:
/branches/bleeding_edge/src/arm/full-codegen-arm.cc
/branches/bleeding_edge/src/hydrogen-instructions.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/hydrogen.h
/branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
/branches/bleeding_edge/src/mips/full-codegen-mips.cc
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/x64/full-codegen-x64.cc
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Fri Apr 12 07:46:43
2013
+++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Wed Apr 17 05:47:15
2013
@@ -3975,18 +3975,6 @@
context()->Plug(r0);
break;
}
-
- case Token::ADD: {
- Comment cmt(masm_, "[ UnaryOperation (ADD)");
- VisitForAccumulatorValue(expr->expression());
- Label no_conversion;
- __ JumpIfSmi(result_register(), &no_conversion);
- ToNumberStub convert_stub;
- __ CallStub(&convert_stub);
- __ bind(&no_conversion);
- context()->Plug(result_register());
- break;
- }
case Token::SUB:
EmitUnaryOperation(expr, "[ UnaryOperation (SUB)");
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Tue Apr 16
04:00:02 2013
+++ /branches/bleeding_edge/src/hydrogen-instructions.cc Wed Apr 17
05:47:15 2013
@@ -1434,6 +1434,21 @@
if (CheckUsesForFlag(kTruncatingToInt32)) ClearFlag(kCanOverflow);
return this;
}
+
+
+// TODO(svenpanne) Use this in other Canonicalize() functions.
+static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t
identity) {
+ return arg1->representation().IsSpecialization() &&
+ arg2->IsInteger32Constant() &&
+ arg2->GetInteger32Constant() == identity;
+}
+
+
+HValue* HMul::Canonicalize() {
+ if (IsIdentityOperation(left(), right(), 1)) return left();
+ if (IsIdentityOperation(right(), left(), 1)) return right();
+ return this;
+}
HValue* HChange::Canonicalize() {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Tue Apr 16 04:00:02
2013
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Wed Apr 17 05:47:15
2013
@@ -4401,6 +4401,8 @@
virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
+ virtual HValue* Canonicalize();
+
// Only commutative if it is certain that not two objects are
multiplicated.
virtual bool IsCommutative() const {
return !representation().IsTagged();
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Tue Apr 16 05:30:51 2013
+++ /branches/bleeding_edge/src/hydrogen.cc Wed Apr 17 05:47:15 2013
@@ -9160,7 +9160,6 @@
case Token::DELETE: return VisitDelete(expr);
case Token::VOID: return VisitVoid(expr);
case Token::TYPEOF: return VisitTypeof(expr);
- case Token::ADD: return VisitAdd(expr);
case Token::SUB: return VisitSub(expr);
case Token::BIT_NOT: return VisitBitNot(expr);
case Token::NOT: return VisitNot(expr);
@@ -9216,21 +9215,6 @@
HInstruction* instr = new(zone()) HTypeof(context, value);
return ast_context()->ReturnInstruction(instr, expr->id());
}
-
-
-void HOptimizedGraphBuilder::VisitAdd(UnaryOperation* expr) {
- CHECK_ALIVE(VisitForValue(expr->expression()));
- HValue* value = Pop();
- HValue* context = environment()->LookupContext();
- HInstruction* instr =
- HMul::New(zone(), context, value, graph()->GetConstant1());
- if (instr->IsBinaryOperation()) {
- // Since we don't have type feedback, we must be cautious/pessimistic.
- HBinaryOperation::cast(instr)->set_observed_input_representation(
- Representation::Tagged(), Representation::Tagged());
- }
- return ast_context()->ReturnInstruction(instr, expr->id());
-}
void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) {
=======================================
--- /branches/bleeding_edge/src/hydrogen.h Tue Apr 16 04:00:02 2013
+++ /branches/bleeding_edge/src/hydrogen.h Wed Apr 17 05:47:15 2013
@@ -1267,7 +1267,6 @@
void VisitDelete(UnaryOperation* expr);
void VisitVoid(UnaryOperation* expr);
void VisitTypeof(UnaryOperation* expr);
- void VisitAdd(UnaryOperation* expr);
void VisitSub(UnaryOperation* expr);
void VisitBitNot(UnaryOperation* expr);
void VisitNot(UnaryOperation* expr);
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Apr 11
09:28:19 2013
+++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Wed Apr 17
05:47:15 2013
@@ -3966,18 +3966,6 @@
context()->Plug(eax);
break;
}
-
- case Token::ADD: {
- Comment cmt(masm_, "[ UnaryOperation (ADD)");
- VisitForAccumulatorValue(expr->expression());
- Label no_conversion;
- __ JumpIfSmi(result_register(), &no_conversion);
- ToNumberStub convert_stub;
- __ CallStub(&convert_stub);
- __ bind(&no_conversion);
- context()->Plug(result_register());
- break;
- }
case Token::SUB:
EmitUnaryOperation(expr, "[ UnaryOperation (SUB)");
=======================================
--- /branches/bleeding_edge/src/mips/full-codegen-mips.cc Tue Apr 16
04:33:02 2013
+++ /branches/bleeding_edge/src/mips/full-codegen-mips.cc Wed Apr 17
05:47:15 2013
@@ -3994,19 +3994,6 @@
context()->Plug(v0);
break;
}
-
- case Token::ADD: {
- Comment cmt(masm_, "[ UnaryOperation (ADD)");
- VisitForAccumulatorValue(expr->expression());
- Label no_conversion;
- __ JumpIfSmi(result_register(), &no_conversion);
- __ mov(a0, result_register());
- ToNumberStub convert_stub;
- __ CallStub(&convert_stub);
- __ bind(&no_conversion);
- context()->Plug(result_register());
- break;
- }
case Token::SUB:
EmitUnaryOperation(expr, "[ UnaryOperation (SUB)");
=======================================
--- /branches/bleeding_edge/src/parser.cc Mon Apr 15 05:29:44 2013
+++ /branches/bleeding_edge/src/parser.cc Wed Apr 17 05:47:15 2013
@@ -3285,6 +3285,16 @@
return NULL;
}
}
+
+ // Desugar '+foo' into 'foo*1', this enables the collection of type
feedback
+ // without any special stub and the multiplication is removed later in
+ // Crankshaft's canonicalization pass.
+ if (op == Token::ADD) {
+ return factory()->NewBinaryOperation(Token::MUL,
+ expression,
+ factory()->NewNumberLiteral(1),
+ position);
+ }
return factory()->NewUnaryOperation(op, expression, position);
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Apr 11 09:28:19
2013
+++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Wed Apr 17 05:47:15
2013
@@ -3967,18 +3967,6 @@
context()->Plug(rax);
break;
}
-
- case Token::ADD: {
- Comment cmt(masm_, "[ UnaryOperation (ADD)");
- VisitForAccumulatorValue(expr->expression());
- Label no_conversion;
- __ JumpIfSmi(result_register(), &no_conversion);
- ToNumberStub convert_stub;
- __ CallStub(&convert_stub);
- __ bind(&no_conversion);
- context()->Plug(result_register());
- break;
- }
case Token::SUB:
EmitUnaryOperation(expr, "[ UnaryOperation (SUB)");
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.