From 335c2b44df6d1e379d2bd8e5cbba47a6fbb92a67 Mon Sep 17 00:00:00 2001 From: Jan De Mooij Date: Thu, 5 Aug 2010 16:09:47 -0700 Subject: [PATCH] [JAEGER] Constant fold neg on ints better (bug 584838, r=dvander). --- js/src/methodjit/Compiler.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/js/src/methodjit/Compiler.cpp b/js/src/methodjit/Compiler.cpp index 070b00174d6..3a141f759fd 100644 --- a/js/src/methodjit/Compiler.cpp +++ b/js/src/methodjit/Compiler.cpp @@ -703,11 +703,21 @@ mjit::Compiler::generateMethod() { FrameEntry *top = frame.peek(-1); if (top->isConstant() && top->getValue().isPrimitive()) { - double d; - ValueToNumber(cx, top->getValue(), &d); - d = -d; - frame.pop(); - frame.push(DoubleValue(d)); + if (top->isType(JSVAL_TYPE_INT32) && + top->getValue().toInt32() != 0 && + top->getValue().toInt32() != (1 << 31)) + { + int32 value = top->getValue().toInt32(); + value = -value; + frame.pop(); + frame.push(Int32Value(value)); + } else { + double d; + ValueToNumber(cx, top->getValue(), &d); + d = -d; + frame.pop(); + frame.push(DoubleValue(d)); + } } else { jsop_neg(); }