Commit 56569966 authored by verwaest@chromium.org's avatar verwaest@chromium.org

Fix Smi-based MathMinMax on x64, and reenable smi mode.

BUG=
R=jkummerow@chromium.org

Review URL: https://chromiumcodereview.appspot.com/20706002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15905 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2aab9298
......@@ -4792,8 +4792,7 @@ class HMathMinMax: public HArithmeticBinaryOperation {
virtual Representation RepresentationFromInputs() {
Representation left_rep = left()->representation();
Representation right_rep = right()->representation();
// TODO(verwaest): Initialize to Smi once lithium-codegen has been fixed.
Representation result = Representation::Integer32();
Representation result = Representation::Smi();
result = result.generalize(left_rep);
result = result.generalize(right_rep);
if (result.IsTagged()) return Representation::Double();
......
......@@ -1699,7 +1699,7 @@ void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
LOperand* right = instr->right();
ASSERT(left->Equals(instr->result()));
HMathMinMax::Operation operation = instr->hydrogen()->operation();
if (instr->hydrogen()->representation().IsInteger32()) {
if (instr->hydrogen()->representation().IsSmiOrInteger32()) {
Label return_left;
Condition condition = (operation == HMathMinMax::kMathMin)
? less_equal
......@@ -1708,17 +1708,26 @@ void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
if (right->IsConstantOperand()) {
Immediate right_imm =
Immediate(ToInteger32(LConstantOperand::cast(right)));
ASSERT(!instr->hydrogen_value()->representation().IsSmi());
__ cmpl(left_reg, right_imm);
__ j(condition, &return_left, Label::kNear);
__ movq(left_reg, right_imm);
} else if (right->IsRegister()) {
Register right_reg = ToRegister(right);
__ cmpl(left_reg, right_reg);
if (instr->hydrogen_value()->representation().IsSmi()) {
__ cmpq(left_reg, right_reg);
} else {
__ cmpl(left_reg, right_reg);
}
__ j(condition, &return_left, Label::kNear);
__ movq(left_reg, right_reg);
} else {
Operand right_op = ToOperand(right);
__ cmpl(left_reg, right_op);
if (instr->hydrogen_value()->representation().IsSmi()) {
__ cmpq(left_reg, right_op);
} else {
__ cmpl(left_reg, right_op);
}
__ j(condition, &return_left, Label::kNear);
__ movq(left_reg, right_op);
}
......
......@@ -1562,9 +1562,9 @@ LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
LOperand* left = NULL;
LOperand* right = NULL;
if (instr->representation().IsInteger32()) {
ASSERT(instr->left()->representation().IsInteger32());
ASSERT(instr->right()->representation().IsInteger32());
if (instr->representation().IsSmiOrInteger32()) {
ASSERT(instr->left()->representation().Equals(instr->representation()));
ASSERT(instr->right()->representation().Equals(instr->representation()));
left = UseRegisterAtStart(instr->BetterLeftOperand());
right = UseOrConstantAtStart(instr->BetterRightOperand());
} else {
......
......@@ -177,6 +177,21 @@ function crankshaft_test_2() {
run(crankshaft_test_2);
var o = { a: 1, b: 2 };
// Test smi-based Math.min.
function f(o) {
return Math.min(o.a, o.b);
}
assertEquals(1, f(o));
assertEquals(1, f(o));
%OptimizeFunctionOnNextCall(f);
assertEquals(1, f(o));
o.a = 5;
o.b = 4;
assertEquals(4, f(o));
// Test overriding Math.min and Math.max
Math.min = function(a, b) { return a + b; }
Math.max = function(a, b) { return a - b; }
......
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