Revision: 16021
Author: [email protected]
Date: Fri Aug 2 01:59:02 2013
Log: Avoid redundant smi check for Math.abs
[email protected]
Review URL: https://codereview.chromium.org/21180004
Patch from Weiliang Lin <[email protected]>.
http://code.google.com/p/v8/source/detail?r=16021
Modified:
/branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.h
/branches/bleeding_edge/test/mjsunit/math-abs.js
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Thu Aug 1
01:42:47 2013
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Fri Aug 2
01:59:02 2013
@@ -3765,7 +3765,7 @@
DwVfpRegister input = ToDoubleRegister(instr->value());
DwVfpRegister result = ToDoubleRegister(instr->result());
__ vabs(result, input);
- } else if (r.IsInteger32()) {
+ } else if (r.IsSmiOrInteger32()) {
EmitIntegerMathAbs(instr);
} else {
// Representation is tagged.
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Aug 1
05:55:19 2013
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Fri Aug 2
01:59:02 2013
@@ -3821,7 +3821,7 @@
__ xorps(scratch, scratch);
__ subsd(scratch, input_reg);
__ pand(input_reg, scratch);
- } else if (r.IsInteger32()) {
+ } else if (r.IsSmiOrInteger32()) {
EmitIntegerMathAbs(instr);
} else { // Tagged case.
DeferredMathAbsTaggedHeapNumber* deferred =
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Aug 1
05:55:19 2013
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Fri Aug 2
01:59:02 2013
@@ -3424,6 +3424,17 @@
DeoptimizeIf(negative, instr->environment());
__ bind(&is_positive);
}
+
+
+void LCodeGen::EmitInteger64MathAbs(LMathAbs* instr) {
+ Register input_reg = ToRegister(instr->value());
+ __ testq(input_reg, input_reg);
+ Label is_positive;
+ __ j(not_sign, &is_positive, Label::kNear);
+ __ neg(input_reg); // Sets flags.
+ DeoptimizeIf(negative, instr->environment());
+ __ bind(&is_positive);
+}
void LCodeGen::DoMathAbs(LMathAbs* instr) {
@@ -3451,6 +3462,8 @@
__ andpd(input_reg, scratch);
} else if (r.IsInteger32()) {
EmitIntegerMathAbs(instr);
+ } else if (r.IsSmi()) {
+ EmitInteger64MathAbs(instr);
} else { // Tagged case.
DeferredMathAbsTaggedHeapNumber* deferred =
new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr);
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Thu Aug 1
05:55:19 2013
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Fri Aug 2
01:59:02 2013
@@ -268,6 +268,7 @@
uint32_t additional_index = 0);
void EmitIntegerMathAbs(LMathAbs* instr);
+ void EmitInteger64MathAbs(LMathAbs* instr);
// Support for recording safepoint and position information.
void RecordSafepoint(LPointerMap* pointers,
=======================================
--- /branches/bleeding_edge/test/mjsunit/math-abs.js Fri Jun 24 00:46:57
2011
+++ /branches/bleeding_edge/test/mjsunit/math-abs.js Fri Aug 2 01:59:02
2013
@@ -109,3 +109,14 @@
assertEquals(42, foo(-42));
%OptimizeFunctionOnNextCall(foo)
assertEquals(42, foo(-42));
+
+// Regression test for SMI input of Math.abs on X64, see:
+// https://codereview.chromium.org/21180004/
+var a = [-1, -2];
+function foo2() {
+ return Math.abs(a[0]);
+}
+assertEquals(1, foo2());
+assertEquals(1, foo2());
+%OptimizeFunctionOnNextCall(foo2);
+assertEquals(1, foo2());
--
--
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.