tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 020bda6ff0b5dae780fc2f410c3a3e4d1f0a80a3
parent 395d9507f3e52a314c44e9e6cd31646b200624b4
Author: André Bargull <andre.bargull@gmail.com>
Date:   Tue, 11 Nov 2025 12:29:34 +0000

Bug 1998161 - Part 2: Use register allocator to place lhs operand for div/mod into eax. r=spidermonkey-reviewers,iain

Instead of manually moving the lhs operand into `eax`, use `useFixedAtStart`
to perform the register move through the register allocator.

Differential Revision: https://phabricator.services.mozilla.com/D271220

Diffstat:
Mjs/src/jit/x64/CodeGenerator-x64.cpp | 34++++++++--------------------------
Mjs/src/jit/x64/Lowering-x64.cpp | 12++++++------
Mjs/src/jit/x86-shared/CodeGenerator-x86-shared.cpp | 38++++++++------------------------------
Mjs/src/jit/x86-shared/Lowering-x86-shared.cpp | 16++++++++--------
4 files changed, 30 insertions(+), 70 deletions(-)

diff --git a/js/src/jit/x64/CodeGenerator-x64.cpp b/js/src/jit/x64/CodeGenerator-x64.cpp @@ -212,7 +212,8 @@ void CodeGenerator::visitDivI64(LDivI64* lir) { Register lhs = ToRegister(lir->lhs()); Register rhs = ToRegister(lir->rhs()); - MOZ_ASSERT_IF(lhs != rhs, rhs != rax); + MOZ_ASSERT(lhs == rax); + MOZ_ASSERT(rhs != rax); MOZ_ASSERT(rhs != rdx); MOZ_ASSERT(ToRegister(lir->output()) == rax); MOZ_ASSERT(ToRegister(lir->temp0()) == rdx); @@ -231,11 +232,6 @@ void CodeGenerator::visitDivI64(LDivI64* lir) { masm.bind(&notOverflow); } - // Put the lhs in rax. - if (lhs != rax) { - masm.mov(lhs, rax); - } - // Sign extend the lhs into rdx to make rdx:rax. masm.cqo(); masm.idivq(rhs); @@ -246,7 +242,8 @@ void CodeGenerator::visitModI64(LModI64* lir) { Register rhs = ToRegister(lir->rhs()); Register output = ToRegister(lir->output()); - MOZ_ASSERT_IF(lhs != rhs, rhs != rax); + MOZ_ASSERT(lhs == rax); + MOZ_ASSERT(rhs != rax); MOZ_ASSERT(rhs != rdx); MOZ_ASSERT(ToRegister(lir->output()) == rdx); MOZ_ASSERT(ToRegister(lir->temp0()) == rax); @@ -270,11 +267,6 @@ void CodeGenerator::visitModI64(LModI64* lir) { masm.bind(&notOverflow); } - // Put the lhs in rax. - if (lhs != rax) { - masm.mov(lhs, rax); - } - // Sign extend the lhs into rdx to make rdx:rax. masm.cqo(); masm.idivq(rhs); @@ -283,10 +275,10 @@ void CodeGenerator::visitModI64(LModI64* lir) { } void CodeGenerator::visitUDivI64(LUDivI64* lir) { - Register lhs = ToRegister(lir->lhs()); Register rhs = ToRegister(lir->rhs()); - MOZ_ASSERT_IF(lhs != rhs, rhs != rax); + MOZ_ASSERT(ToRegister(lir->lhs()) == rax); + MOZ_ASSERT(rhs != rax); MOZ_ASSERT(rhs != rdx); MOZ_ASSERT(ToRegister(lir->output()) == rax); MOZ_ASSERT(ToRegister(lir->temp0()) == rdx); @@ -294,21 +286,16 @@ void CodeGenerator::visitUDivI64(LUDivI64* lir) { // Prevent divide by zero. TrapIfDivideByZero(masm, lir, rhs); - // Put the lhs in rax. - if (lhs != rax) { - masm.mov(lhs, rax); - } - // Zero extend the lhs into rdx to make (rdx:rax). masm.xorl(rdx, rdx); masm.udivq(rhs); } void CodeGenerator::visitUModI64(LUModI64* lir) { - Register lhs = ToRegister(lir->lhs()); Register rhs = ToRegister(lir->rhs()); - MOZ_ASSERT_IF(lhs != rhs, rhs != rax); + MOZ_ASSERT(ToRegister(lir->lhs()) == rax); + MOZ_ASSERT(rhs != rax); MOZ_ASSERT(rhs != rdx); MOZ_ASSERT(ToRegister(lir->output()) == rdx); MOZ_ASSERT(ToRegister(lir->temp0()) == rax); @@ -316,11 +303,6 @@ void CodeGenerator::visitUModI64(LUModI64* lir) { // Prevent divide by zero. TrapIfDivideByZero(masm, lir, rhs); - // Put the lhs in rax. - if (lhs != rax) { - masm.mov(lhs, rax); - } - // Zero extend the lhs into rdx to make (rdx:rax). masm.xorl(rdx, rdx); masm.udivq(rhs); diff --git a/js/src/jit/x64/Lowering-x64.cpp b/js/src/jit/x64/Lowering-x64.cpp @@ -526,8 +526,8 @@ void LIRGenerator::visitSubstr(MSubstr* ins) { } void LIRGeneratorX64::lowerDivI64(MDiv* div) { - auto* lir = new (alloc()) - LDivI64(useRegister(div->lhs()), useRegister(div->rhs()), tempFixed(rdx)); + auto* lir = new (alloc()) LDivI64(useFixedAtStart(div->lhs(), rax), + useRegister(div->rhs()), tempFixed(rdx)); defineInt64Fixed(lir, div, LInt64Allocation(LAllocation(AnyRegister(rax)))); } @@ -536,8 +536,8 @@ void LIRGeneratorX64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) { } void LIRGeneratorX64::lowerModI64(MMod* mod) { - auto* lir = new (alloc()) - LModI64(useRegister(mod->lhs()), useRegister(mod->rhs()), tempFixed(rax)); + auto* lir = new (alloc()) LModI64(useFixedAtStart(mod->lhs(), rax), + useRegister(mod->rhs()), tempFixed(rax)); defineInt64Fixed(lir, mod, LInt64Allocation(LAllocation(AnyRegister(rdx)))); } @@ -546,13 +546,13 @@ void LIRGeneratorX64::lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) { } void LIRGeneratorX64::lowerUDivI64(MDiv* div) { - auto* lir = new (alloc()) LUDivI64(useRegister(div->lhs()), + auto* lir = new (alloc()) LUDivI64(useFixedAtStart(div->lhs(), rax), useRegister(div->rhs()), tempFixed(rdx)); defineInt64Fixed(lir, div, LInt64Allocation(LAllocation(AnyRegister(rax)))); } void LIRGeneratorX64::lowerUModI64(MMod* mod) { - auto* lir = new (alloc()) LUModI64(useRegister(mod->lhs()), + auto* lir = new (alloc()) LUModI64(useFixedAtStart(mod->lhs(), rax), useRegister(mod->rhs()), tempFixed(rax)); defineInt64Fixed(lir, mod, LInt64Allocation(LAllocation(AnyRegister(rdx)))); } diff --git a/js/src/jit/x86-shared/CodeGenerator-x86-shared.cpp b/js/src/jit/x86-shared/CodeGenerator-x86-shared.cpp @@ -897,12 +897,12 @@ OutOfLineCode* CodeGeneratorX86Shared::emitOutOfLineZeroForDivideByZero( } void CodeGenerator::visitUDiv(LUDiv* ins) { - Register lhs = ToRegister(ins->lhs()); Register rhs = ToRegister(ins->rhs()); Register output = ToRegister(ins->output()); Register remainder = ToRegister(ins->temp0()); - MOZ_ASSERT_IF(lhs != rhs, rhs != eax); + MOZ_ASSERT(ToRegister(ins->lhs()) == eax); + MOZ_ASSERT(rhs != eax); MOZ_ASSERT(rhs != edx); MOZ_ASSERT(output == eax); MOZ_ASSERT(remainder == edx); @@ -911,11 +911,6 @@ void CodeGenerator::visitUDiv(LUDiv* ins) { OutOfLineCode* ool = nullptr; - // Put the lhs in eax. - if (lhs != eax) { - masm.mov(lhs, eax); - } - // Prevent divide by zero. if (mir->canBeDivideByZero()) { if (mir->trapOnError()) { @@ -950,11 +945,11 @@ void CodeGenerator::visitUDiv(LUDiv* ins) { } void CodeGenerator::visitUMod(LUMod* ins) { - Register lhs = ToRegister(ins->lhs()); Register rhs = ToRegister(ins->rhs()); Register output = ToRegister(ins->output()); - MOZ_ASSERT_IF(lhs != rhs, rhs != eax); + MOZ_ASSERT(ToRegister(ins->lhs()) == eax); + MOZ_ASSERT(rhs != eax); MOZ_ASSERT(rhs != edx); MOZ_ASSERT(output == edx); MOZ_ASSERT(ToRegister(ins->temp0()) == eax); @@ -963,11 +958,6 @@ void CodeGenerator::visitUMod(LUMod* ins) { OutOfLineCode* ool = nullptr; - // Put the lhs in eax. - if (lhs != eax) { - masm.mov(lhs, eax); - } - // Prevent divide by zero. if (mir->canBeDivideByZero()) { if (mir->trapOnError()) { @@ -1321,7 +1311,8 @@ void CodeGenerator::visitDivI(LDivI* ins) { Register rhs = ToRegister(ins->rhs()); Register output = ToRegister(ins->output()); - MOZ_ASSERT_IF(lhs != rhs, rhs != eax); + MOZ_ASSERT(lhs == eax); + MOZ_ASSERT(rhs != eax); MOZ_ASSERT(rhs != edx); MOZ_ASSERT(remainder == edx); MOZ_ASSERT(output == eax); @@ -1331,12 +1322,6 @@ void CodeGenerator::visitDivI(LDivI* ins) { Label done; OutOfLineCode* ool = nullptr; - // Put the lhs in eax, for either the negative overflow case or the regular - // divide case. - if (lhs != eax) { - masm.mov(lhs, eax); - } - // Handle divide by zero. if (mir->canBeDivideByZero()) { if (mir->trapOnError()) { @@ -1376,9 +1361,6 @@ void CodeGenerator::visitDivI(LDivI* ins) { } // Sign extend the lhs into edx to make (edx:eax), since idiv is 64-bit. - if (lhs != eax) { - masm.mov(lhs, eax); - } masm.cdq(); masm.idiv(rhs); @@ -1469,7 +1451,8 @@ void CodeGenerator::visitModI(LModI* ins) { Register rhs = ToRegister(ins->rhs()); // Required to use idiv. - MOZ_ASSERT_IF(lhs != rhs, rhs != eax); + MOZ_ASSERT(lhs == eax); + MOZ_ASSERT(rhs != eax); MOZ_ASSERT(rhs != edx); MOZ_ASSERT(remainder == edx); MOZ_ASSERT(ToRegister(ins->temp0()) == eax); @@ -1480,11 +1463,6 @@ void CodeGenerator::visitModI(LModI* ins) { OutOfLineCode* ool = nullptr; ModOverflowCheck* overflow = nullptr; - // Set up eax in preparation for doing a div. - if (lhs != eax) { - masm.mov(lhs, eax); - } - // Prevent divide by zero. if (mir->canBeDivideByZero()) { if (mir->trapOnError()) { diff --git a/js/src/jit/x86-shared/Lowering-x86-shared.cpp b/js/src/jit/x86-shared/Lowering-x86-shared.cpp @@ -210,8 +210,8 @@ void LIRGeneratorX86Shared::lowerDivI(MDiv* div) { return; } - LDivI* lir = new (alloc()) - LDivI(useRegister(div->lhs()), useRegister(div->rhs()), tempFixed(edx)); + auto* lir = new (alloc()) LDivI(useFixedAtStart(div->lhs(), eax), + useRegister(div->rhs()), tempFixed(edx)); if (div->fallible()) { assignSnapshot(lir, div->bailoutKind()); } @@ -241,8 +241,8 @@ void LIRGeneratorX86Shared::lowerModI(MMod* mod) { return; } - LModI* lir = new (alloc()) - LModI(useRegister(mod->lhs()), useRegister(mod->rhs()), tempFixed(eax)); + auto* lir = new (alloc()) LModI(useFixedAtStart(mod->lhs(), eax), + useRegister(mod->rhs()), tempFixed(eax)); if (mod->fallible()) { assignSnapshot(lir, mod->bailoutKind()); } @@ -373,8 +373,8 @@ void LIRGeneratorX86Shared::lowerUDiv(MDiv* div) { return; } - auto* lir = new (alloc()) - LUDiv(useRegister(div->lhs()), useRegister(div->rhs()), tempFixed(edx)); + auto* lir = new (alloc()) LUDiv(useFixedAtStart(div->lhs(), eax), + useRegister(div->rhs()), tempFixed(edx)); if (div->fallible()) { assignSnapshot(lir, div->bailoutKind()); } @@ -404,8 +404,8 @@ void LIRGeneratorX86Shared::lowerUMod(MMod* mod) { return; } - auto* lir = new (alloc()) - LUMod(useRegister(mod->lhs()), useRegister(mod->rhs()), tempFixed(eax)); + auto* lir = new (alloc()) LUMod(useFixedAtStart(mod->lhs(), eax), + useRegister(mod->rhs()), tempFixed(eax)); if (mod->fallible()) { assignSnapshot(lir, mod->bailoutKind()); }