commit 5750dbfd6d101f9c823c0b97916b3198148f8e83
parent ae9d2ab59ec2bb9f30e650c67ff9bf963e092567
Author: André Bargull <andre.bargull@gmail.com>
Date: Wed, 5 Nov 2025 20:55:55 +0000
Bug 1997975 - Part 3: Align LModI/LUMod with LDivI/LUDiv on arm64. r=spidermonkey-reviewers,iain
Align the code structure for modulus instructions to be more similar to the
corresponding division instructions.
Differential Revision: https://phabricator.services.mozilla.com/D271104
Diffstat:
2 files changed, 44 insertions(+), 42 deletions(-)
diff --git a/js/src/jit/arm64/CodeGenerator-arm64.cpp b/js/src/jit/arm64/CodeGenerator-arm64.cpp
@@ -641,39 +641,39 @@ void CodeGenerator::visitUDivConstantI(LUDivConstantI* ins) {
}
void CodeGenerator::visitModI(LModI* ins) {
- ARMRegister lhs = toWRegister(ins->lhs());
- ARMRegister rhs = toWRegister(ins->rhs());
- ARMRegister output = toWRegister(ins->output());
+ Register lhs = ToRegister(ins->lhs());
+ Register rhs = ToRegister(ins->rhs());
+
+ ARMRegister lhs32 = toWRegister(ins->lhs());
+ ARMRegister rhs32 = toWRegister(ins->rhs());
+ ARMRegister output32 = toWRegister(ins->output());
Label done;
MMod* mir = ins->mir();
// Prevent divide by zero.
if (mir->canBeDivideByZero()) {
- if (mir->isTruncated()) {
- if (mir->trapOnError()) {
- Label nonZero;
- masm.Cbnz(rhs, &nonZero);
- masm.wasmTrap(wasm::Trap::IntegerDivideByZero, mir->trapSiteDesc());
- masm.bind(&nonZero);
- } else {
- // Truncated division by zero yields integer zero.
- masm.Mov(output, rhs);
- masm.Cbz(rhs, &done);
- }
+ if (mir->trapOnError()) {
+ Label nonZero;
+ masm.Cbnz(rhs32, &nonZero);
+ masm.wasmTrap(wasm::Trap::IntegerDivideByZero, mir->trapSiteDesc());
+ masm.bind(&nonZero);
+ } else if (mir->isTruncated()) {
+ // Truncated division by zero yields integer zero.
+ masm.Mov(output32, wzr);
+ masm.Cbz(rhs32, &done);
} else {
// Non-truncated division by zero produces a non-integer.
- MOZ_ASSERT(!gen->compilingWasm());
- masm.Cmp(rhs, Operand(0));
- bailoutIf(Assembler::Equal, ins->snapshot());
+ MOZ_ASSERT(mir->fallible());
+ bailoutTest32(Assembler::Zero, rhs, rhs, ins->snapshot());
}
}
// Signed division.
- masm.Sdiv(output, lhs, rhs);
+ masm.Sdiv(output32, lhs32, rhs32);
// Compute the remainder: output = lhs - (output * rhs).
- masm.Msub(output, output, rhs, lhs);
+ masm.Msub(output32, output32, rhs32, lhs32);
if (mir->canBeNegativeDividend() && !mir->isTruncated()) {
// If output == 0 and lhs < 0, then the result should be double -0.0.
@@ -681,7 +681,7 @@ void CodeGenerator::visitModI(LModI* ins) {
// output = INT_MIN - (INT_MIN / -1) * -1
// = INT_MIN - INT_MIN
// = 0
- masm.Cbnz(output, &done);
+ masm.Cbnz(output32, &done);
bailoutCmp32(Assembler::LessThan, lhs, Imm32(0), ins->snapshot());
}
@@ -1711,36 +1711,37 @@ void CodeGenerator::visitUDiv(LUDiv* ins) {
}
void CodeGenerator::visitUMod(LUMod* ins) {
- MMod* mir = ins->mir();
- ARMRegister lhs = toWRegister(ins->lhs());
- ARMRegister rhs = toWRegister(ins->rhs());
- ARMRegister output = toWRegister(ins->output());
+ Register rhs = ToRegister(ins->rhs());
+ Register output = ToRegister(ins->output());
+
+ ARMRegister lhs32 = toWRegister(ins->lhs());
+ ARMRegister rhs32 = toWRegister(ins->rhs());
+ ARMRegister output32 = toWRegister(ins->output());
Label done;
+ MMod* mir = ins->mir();
+
if (mir->canBeDivideByZero()) {
- if (mir->isTruncated()) {
- if (mir->trapOnError()) {
- Label nonZero;
- masm.Cbnz(rhs, &nonZero);
- masm.wasmTrap(wasm::Trap::IntegerDivideByZero, mir->trapSiteDesc());
- masm.bind(&nonZero);
- } else {
- // Truncated division by zero yields integer zero.
- masm.Mov(output, rhs);
- masm.Cbz(rhs, &done);
- }
+ if (mir->trapOnError()) {
+ Label nonZero;
+ masm.Cbnz(rhs32, &nonZero);
+ masm.wasmTrap(wasm::Trap::IntegerDivideByZero, mir->trapSiteDesc());
+ masm.bind(&nonZero);
+ } else if (mir->isTruncated()) {
+ // Truncated division by zero yields integer zero.
+ masm.Mov(output32, wzr);
+ masm.Cbz(rhs32, &done);
} else {
// Non-truncated division by zero produces a non-integer.
- masm.Cmp(rhs, Operand(0));
- bailoutIf(Assembler::Equal, ins->snapshot());
+ bailoutTest32(Assembler::Zero, rhs, rhs, ins->snapshot());
}
}
// Unsigned division.
- masm.Udiv(output, lhs, rhs);
+ masm.Udiv(output32, lhs32, rhs32);
// Compute the remainder: output = lhs - (output * rhs).
- masm.Msub(output, output, rhs, lhs);
+ masm.Msub(output32, output32, rhs32, lhs32);
if (!mir->isTruncated()) {
// Bail if the output would be negative.
diff --git a/js/src/jit/arm64/Lowering-arm64.cpp b/js/src/jit/arm64/Lowering-arm64.cpp
@@ -283,10 +283,11 @@ void LIRGeneratorARM64::lowerModI(MMod* mod) {
assignSnapshot(lir, mod->bailoutKind());
}
define(lir, mod);
+ return;
}
}
- LModI* lir =
+ auto* lir =
new (alloc()) LModI(useRegister(mod->lhs()), useRegister(mod->rhs()));
if (mod->fallible()) {
assignSnapshot(lir, mod->bailoutKind());
@@ -536,8 +537,8 @@ void LIRGeneratorARM64::lowerUDiv(MDiv* div) {
}
void LIRGeneratorARM64::lowerUMod(MMod* mod) {
- LUMod* lir = new (alloc())
- LUMod(useRegister(mod->getOperand(0)), useRegister(mod->getOperand(1)));
+ auto* lir =
+ new (alloc()) LUMod(useRegister(mod->lhs()), useRegister(mod->rhs()));
if (mod->fallible()) {
assignSnapshot(lir, mod->bailoutKind());
}