bug 1180874 - Use DivOrModConstantI for unsigned division or modulo by constant. r=nbp
authorSander Mathijs van Veen <smvv@kompiler.org>
Tue, 07 Jul 2015 17:03:59 +0200
changeset 251854 596ee431b3d25c957fa8389a75f9f36787e2d33e
parent 251853 ea4f4e3b00907ddb13359a1bee20adeee44dfe0d
child 251855 9ef460929d4e4d7f5025ab6c513cfb10e62fc7e3
push id61986
push usercbook@mozilla.com
push dateWed, 08 Jul 2015 08:04:37 +0000
treeherdermozilla-inbound@4ed2ded0daef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1180874
milestone42.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 1180874 - Use DivOrModConstantI for unsigned division or modulo by constant. r=nbp
js/src/jit/x86-shared/Lowering-x86-shared.cpp
--- a/js/src/jit/x86-shared/Lowering-x86-shared.cpp
+++ b/js/src/jit/x86-shared/Lowering-x86-shared.cpp
@@ -166,21 +166,16 @@ LIRGeneratorX86Shared::lowerMulI(MMul* m
     if (mul->fallible())
         assignSnapshot(lir, Bailout_DoubleOutput);
     defineReuseInput(lir, mul, 0);
 }
 
 void
 LIRGeneratorX86Shared::lowerDivI(MDiv* div)
 {
-    if (div->isUnsigned()) {
-        lowerUDiv(div);
-        return;
-    }
-
     // Division instructions are slow. Division by constant denominators can be
     // rewritten to use other instructions.
     if (div->rhs()->isConstant()) {
         int32_t rhs = div->rhs()->toConstant()->value().toInt32();
 
         // Division by powers of two can be done by shifting, and division by
         // other numbers can be done by a reciprocal multiplication technique.
         int32_t shift = FloorLog2(Abs(rhs));
@@ -205,31 +200,31 @@ LIRGeneratorX86Shared::lowerDivI(MDiv* d
             lir = new(alloc()) LDivOrModConstantI(useRegister(div->lhs()), rhs, tempFixed(eax));
             if (div->fallible())
                 assignSnapshot(lir, Bailout_DoubleOutput);
             defineFixed(lir, div, LAllocation(AnyRegister(edx)));
             return;
         }
     }
 
+    if (div->isUnsigned()) {
+        lowerUDiv(div);
+        return;
+    }
+
     LDivI* lir = new(alloc()) LDivI(useRegister(div->lhs()), useRegister(div->rhs()),
                                     tempFixed(edx));
     if (div->fallible())
         assignSnapshot(lir, Bailout_DoubleOutput);
     defineFixed(lir, div, LAllocation(AnyRegister(eax)));
 }
 
 void
 LIRGeneratorX86Shared::lowerModI(MMod* mod)
 {
-    if (mod->isUnsigned()) {
-        lowerUMod(mod);
-        return;
-    }
-
     if (mod->rhs()->isConstant()) {
         int32_t rhs = mod->rhs()->toConstant()->value().toInt32();
         int32_t shift = FloorLog2(Abs(rhs));
         if (rhs != 0 && uint32_t(1) << shift == Abs(rhs)) {
             LModPowTwoI* lir = new(alloc()) LModPowTwoI(useRegisterAtStart(mod->lhs()), shift);
             if (mod->fallible())
                 assignSnapshot(lir, Bailout_DoubleOutput);
             defineReuseInput(lir, mod, 0);
@@ -240,16 +235,21 @@ LIRGeneratorX86Shared::lowerModI(MMod* m
             lir = new(alloc()) LDivOrModConstantI(useRegister(mod->lhs()), rhs, tempFixed(edx));
             if (mod->fallible())
                 assignSnapshot(lir, Bailout_DoubleOutput);
             defineFixed(lir, mod, LAllocation(AnyRegister(eax)));
             return;
         }
     }
 
+    if (mod->isUnsigned()) {
+        lowerUMod(mod);
+        return;
+    }
+
     LModI* lir = new(alloc()) LModI(useRegister(mod->lhs()),
                                     useRegister(mod->rhs()),
                                     tempFixed(eax));
     if (mod->fallible())
         assignSnapshot(lir, Bailout_DoubleOutput);
     defineFixed(lir, mod, LAllocation(AnyRegister(edx)));
 }