Bug 813671 - ModI should not clobber input register, r=jandem.
authorBrian Hackett <bhackett1024@gmail.com>
Thu, 13 Dec 2012 09:20:38 -0700
changeset 125040 946bc83d50dfff3ae2183459c006534513314a52
parent 125039 450321f661e89241a05b4d18a339fd6199e002cb
child 125041 09d66d9ccb2ed41c822c44b70693aa72dd8db46c
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs813671
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 813671 - ModI should not clobber input register, r=jandem.
js/src/ion/shared/CodeGenerator-x86-shared.cpp
js/src/ion/shared/LIR-x86-shared.h
js/src/ion/shared/Lowering-x86-shared.cpp
--- a/js/src/ion/shared/CodeGenerator-x86-shared.cpp
+++ b/js/src/ion/shared/CodeGenerator-x86-shared.cpp
@@ -793,20 +793,26 @@ CodeGeneratorX86Shared::visitModPowTwoI(
 }
 
 bool
 CodeGeneratorX86Shared::visitModI(LModI *ins)
 {
     Register remainder = ToRegister(ins->remainder());
     Register lhs = ToRegister(ins->lhs());
     Register rhs = ToRegister(ins->rhs());
+    Register temp = ToRegister(ins->getTemp(0));
 
     // Required to use idiv.
     JS_ASSERT(remainder == edx);
-    JS_ASSERT(lhs == eax);
+    JS_ASSERT(temp == eax);
+
+    if (lhs != temp) {
+        masm.mov(lhs, temp);
+        lhs = temp;
+    }
 
     // If rhs == 0, bailout, since result must be a double (NaN).
     masm.testl(rhs, rhs);
     if (!bailoutIf(Assembler::Zero, ins->snapshot()))
         return false;
 
     Label negative, join;
 
--- a/js/src/ion/shared/LIR-x86-shared.h
+++ b/js/src/ion/shared/LIR-x86-shared.h
@@ -30,19 +30,20 @@ class LDivI : public LBinaryMath<1>
     }
 };
 
 class LModI : public LBinaryMath<1>
 {
   public:
     LIR_HEADER(ModI)
 
-    LModI(const LAllocation &lhs, const LAllocation &rhs) {
+    LModI(const LAllocation &lhs, const LAllocation &rhs, const LDefinition &temp) {
         setOperand(0, lhs);
         setOperand(1, rhs);
+        setTemp(0, temp);
     }
 
     const LDefinition *remainder() {
         return getDef(0);
     }
 };
 
 class LModPowTwoI : public LInstructionHelper<1,1,0>
--- a/js/src/ion/shared/Lowering-x86-shared.cpp
+++ b/js/src/ion/shared/Lowering-x86-shared.cpp
@@ -83,17 +83,17 @@ LIRGeneratorX86Shared::lowerModI(MMod *m
         int32_t rhs = mod->rhs()->toConstant()->value().toInt32();
         int32_t shift;
         JS_FLOOR_LOG2(shift, rhs);
         if (1 << shift == rhs) {
             LModPowTwoI *lir = new LModPowTwoI(useRegisterAtStart(mod->lhs()), shift);
             return assignSnapshot(lir) && defineReuseInput(lir, mod, 0);
         }
     }
-    LModI *lir = new LModI(useFixed(mod->lhs(), eax), useRegister(mod->rhs()));
+    LModI *lir = new LModI(useRegister(mod->lhs()), useRegister(mod->rhs()), tempFixed(eax));
     return assignSnapshot(lir) && defineFixed(lir, mod, LAllocation(AnyRegister(edx)));
 }
 
 bool
 LIRGeneratorX86Shared::lowerUrshD(MUrsh *mir)
 {
     MDefinition *lhs = mir->lhs();
     MDefinition *rhs = mir->rhs();