commit 437b62f789a51f7521fadbea930851e7b81d2b4c
parent 0bccc18ab3e52a71db292af7f2ed045ffe113bfd
Author: André Bargull <andre.bargull@gmail.com>
Date: Fri, 24 Oct 2025 14:58:57 +0000
Bug 1996090 - Part 2: Use at-start allocations for LUDivOrMod on riscv64. r=spidermonkey-reviewers,jandem
Differential Revision: https://phabricator.services.mozilla.com/D269849
Diffstat:
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/js/src/jit/riscv64/CodeGenerator-riscv64.cpp b/js/src/jit/riscv64/CodeGenerator-riscv64.cpp
@@ -2076,15 +2076,25 @@ void CodeGenerator::visitUDivOrMod(LUDivOrMod* ins) {
}
}
- masm.ma_modu32(output, lhs, rhs);
-
// If the remainder is > 0, bailout since this must be a double.
if (ins->mir()->isDiv()) {
- if (!ins->mir()->toDiv()->canTruncateRemainder()) {
- bailoutCmp32(Assembler::NonZero, output, output, ins->snapshot());
+ if (ins->mir()->toDiv()->canTruncateRemainder()) {
+ masm.ma_divu32(output, lhs, rhs);
+ } else {
+ MOZ_ASSERT(lhs != output && rhs != output);
+
+ UseScratchRegisterScope temps(&masm);
+ Register scratch = temps.Acquire();
+
+ // The recommended code sequence to obtain both the quotient and remainder
+ // is div[u] followed by mod[u].
+ masm.ma_divu32(output, lhs, rhs);
+ masm.ma_modu32(scratch, lhs, rhs);
+
+ bailoutCmp32(Assembler::NonZero, scratch, scratch, ins->snapshot());
}
- // Get quotient
- masm.ma_divu32(output, lhs, rhs);
+ } else {
+ masm.ma_modu32(output, lhs, rhs);
}
if (!ins->mir()->isTruncated()) {
diff --git a/js/src/jit/riscv64/Lowering-riscv64.cpp b/js/src/jit/riscv64/Lowering-riscv64.cpp
@@ -271,12 +271,18 @@ void LIRGeneratorRiscv64::lowerModI64(MMod* mod) {
}
void LIRGeneratorRiscv64::lowerUDiv(MDiv* div) {
- MDefinition* lhs = div->getOperand(0);
- MDefinition* rhs = div->getOperand(1);
+ LAllocation lhs, rhs;
+ if (!div->canTruncateRemainder()) {
+ lhs = useRegister(div->lhs());
+ rhs = useRegister(div->rhs());
+ } else {
+ lhs = useRegisterAtStart(div->lhs());
+ rhs = useRegisterAtStart(div->rhs());
+ }
- LUDivOrMod* lir = new (alloc()) LUDivOrMod;
- lir->setOperand(0, useRegister(lhs));
- lir->setOperand(1, useRegister(rhs));
+ auto* lir = new (alloc()) LUDivOrMod;
+ lir->setOperand(0, lhs);
+ lir->setOperand(1, rhs);
if (div->fallible()) {
assignSnapshot(lir, div->bailoutKind());
}
@@ -291,12 +297,9 @@ void LIRGeneratorRiscv64::lowerUDivI64(MDiv* div) {
}
void LIRGeneratorRiscv64::lowerUMod(MMod* mod) {
- MDefinition* lhs = mod->getOperand(0);
- MDefinition* rhs = mod->getOperand(1);
-
- LUDivOrMod* lir = new (alloc()) LUDivOrMod;
- lir->setOperand(0, useRegister(lhs));
- lir->setOperand(1, useRegister(rhs));
+ auto* lir = new (alloc()) LUDivOrMod;
+ lir->setOperand(0, useRegisterAtStart(mod->lhs()));
+ lir->setOperand(1, useRegisterAtStart(mod->rhs()));
if (mod->fallible()) {
assignSnapshot(lir, mod->bailoutKind());
}