commit 3b02754b6711c323d9d26a84c6bd902c2dfe4f7f
parent 10aba4a5488f6eb2a7844e249b9ab25ebc1d99dd
Author: André Bargull <andre.bargull@gmail.com>
Date: Wed, 5 Nov 2025 20:55:54 +0000
Bug 1997975 - Part 1: Move unsigned-check to shared lowering. r=spidermonkey-reviewers,iain
Move the `isUnsigned` check into the common Lowering code to avoid duplicating
it for each architecture.
Differential Revision: https://phabricator.services.mozilla.com/D271102
Diffstat:
11 files changed, 24 insertions(+), 114 deletions(-)
diff --git a/js/src/jit/Lowering.cpp b/js/src/jit/Lowering.cpp
@@ -2454,13 +2454,21 @@ void LIRGenerator::visitDiv(MDiv* ins) {
if (ins->type() == MIRType::Int32) {
MOZ_ASSERT(lhs->type() == MIRType::Int32);
- lowerDivI(ins);
+ if (ins->isUnsigned()) {
+ lowerUDiv(ins);
+ } else {
+ lowerDivI(ins);
+ }
return;
}
if (ins->type() == MIRType::Int64) {
MOZ_ASSERT(lhs->type() == MIRType::Int64);
- lowerDivI64(ins);
+ if (ins->isUnsigned()) {
+ lowerUDivI64(ins);
+ } else {
+ lowerDivI64(ins);
+ }
return;
}
@@ -2512,14 +2520,22 @@ void LIRGenerator::visitMod(MMod* ins) {
if (ins->type() == MIRType::Int32) {
MOZ_ASSERT(ins->type() == MIRType::Int32);
MOZ_ASSERT(ins->lhs()->type() == MIRType::Int32);
- lowerModI(ins);
+ if (ins->isUnsigned()) {
+ lowerUMod(ins);
+ } else {
+ lowerModI(ins);
+ }
return;
}
if (ins->type() == MIRType::Int64) {
MOZ_ASSERT(ins->type() == MIRType::Int64);
MOZ_ASSERT(ins->lhs()->type() == MIRType::Int64);
- lowerModI64(ins);
+ if (ins->isUnsigned()) {
+ lowerUModI64(ins);
+ } else {
+ lowerModI64(ins);
+ }
return;
}
diff --git a/js/src/jit/arm/Lowering-arm.cpp b/js/src/jit/arm/Lowering-arm.cpp
@@ -309,11 +309,6 @@ template void LIRGeneratorARM::lowerForShiftInt64(LRotateI64* ins,
MDefinition* rhs);
void LIRGeneratorARM::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()) {
@@ -374,11 +369,6 @@ void LIRGeneratorARM::lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs) {
}
void LIRGeneratorARM::lowerModI(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUMod(mod);
- return;
- }
-
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->toInt32();
int32_t shift = FloorLog2(rhs);
diff --git a/js/src/jit/arm64/Lowering-arm64.cpp b/js/src/jit/arm64/Lowering-arm64.cpp
@@ -204,11 +204,6 @@ void LIRGeneratorARM64::lowerForShift(LInstructionHelper<1, 2, 0>* ins,
}
void LIRGeneratorARM64::lowerDivI(MDiv* div) {
- if (div->isUnsigned()) {
- lowerUDiv(div);
- return;
- }
-
if (div->rhs()->isConstant()) {
LAllocation lhs = useRegister(div->lhs());
int32_t rhs = div->rhs()->toConstant()->toInt32();
@@ -260,11 +255,6 @@ void LIRGeneratorARM64::lowerMulI(MMul* mul, MDefinition* lhs,
}
void LIRGeneratorARM64::lowerModI(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUMod(mod);
- return;
- }
-
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->toInt32();
int32_t shift = FloorLog2(rhs);
@@ -295,11 +285,6 @@ void LIRGeneratorARM64::lowerModI(MMod* mod) {
}
void LIRGeneratorARM64::lowerDivI64(MDiv* div) {
- if (div->isUnsigned()) {
- lowerUDivI64(div);
- return;
- }
-
LDivOrModI64* lir = new (alloc())
LDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs()));
defineInt64(lir, div);
@@ -322,11 +307,6 @@ void LIRGeneratorARM64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) {
}
void LIRGeneratorARM64::lowerModI64(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUModI64(mod);
- return;
- }
-
LDivOrModI64* lir = new (alloc())
LDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs()));
defineInt64(lir, mod);
diff --git a/js/src/jit/loong64/Lowering-loong64.cpp b/js/src/jit/loong64/Lowering-loong64.cpp
@@ -170,11 +170,6 @@ void LIRGeneratorLOONG64::lowerMulI(MMul* mul, MDefinition* lhs,
}
void LIRGeneratorLOONG64::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()) {
@@ -205,22 +200,12 @@ void LIRGeneratorLOONG64::lowerDivI(MDiv* div) {
}
void LIRGeneratorLOONG64::lowerDivI64(MDiv* div) {
- if (div->isUnsigned()) {
- lowerUDivI64(div);
- return;
- }
-
auto* lir = new (alloc())
LDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs()));
defineInt64(lir, div);
}
void LIRGeneratorLOONG64::lowerModI(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUMod(mod);
- return;
- }
-
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->toInt32();
int32_t shift = FloorLog2(rhs);
@@ -252,11 +237,6 @@ void LIRGeneratorLOONG64::lowerModI(MMod* mod) {
}
void LIRGeneratorLOONG64::lowerModI64(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUModI64(mod);
- return;
- }
-
auto* lir = new (alloc())
LDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs()));
defineInt64(lir, mod);
diff --git a/js/src/jit/mips-shared/Lowering-mips-shared.cpp b/js/src/jit/mips-shared/Lowering-mips-shared.cpp
@@ -138,11 +138,6 @@ void LIRGeneratorMIPSShared::lowerForShift(LInstructionHelper<1, 2, 0>* ins,
}
void LIRGeneratorMIPSShared::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()) {
@@ -192,11 +187,6 @@ void LIRGeneratorMIPSShared::lowerMulI(MMul* mul, MDefinition* lhs,
}
void LIRGeneratorMIPSShared::lowerModI(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUMod(mod);
- return;
- }
-
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->toInt32();
int32_t shift = FloorLog2(rhs);
diff --git a/js/src/jit/mips64/Lowering-mips64.cpp b/js/src/jit/mips64/Lowering-mips64.cpp
@@ -36,11 +36,6 @@ LBoxAllocation LIRGeneratorMIPS64::useBoxFixed(MDefinition* mir, Register reg1,
LDefinition LIRGeneratorMIPS64::tempToUnbox() { return temp(); }
void LIRGeneratorMIPS64::lowerDivI64(MDiv* div) {
- if (div->isUnsigned()) {
- lowerUDivI64(div);
- return;
- }
-
auto* lir = new (alloc())
LDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs()));
defineInt64(lir, div);
@@ -51,11 +46,6 @@ void LIRGeneratorMIPS64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) {
}
void LIRGeneratorMIPS64::lowerModI64(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUModI64(mod);
- return;
- }
-
auto* lir = new (alloc())
LDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs()));
defineInt64(lir, mod);
diff --git a/js/src/jit/none/Lowering-none.h b/js/src/jit/none/Lowering-none.h
@@ -86,6 +86,8 @@ class LIRGeneratorNone : public LIRGeneratorShared {
void lowerMulI(MMul*, MDefinition*, MDefinition*) { MOZ_CRASH(); }
void lowerUDiv(MDiv*) { MOZ_CRASH(); }
void lowerUMod(MMod*) { MOZ_CRASH(); }
+ void lowerUDivI64(MDiv*) { MOZ_CRASH(); }
+ void lowerUModI64(MMod*) { MOZ_CRASH(); }
void lowerWasmSelectI(MWasmSelect* select) { MOZ_CRASH(); }
void lowerWasmSelectI64(MWasmSelect* select) { MOZ_CRASH(); }
void lowerWasmCompareAndSelect(MWasmSelect* ins, MDefinition* lhs,
diff --git a/js/src/jit/riscv64/Lowering-riscv64.cpp b/js/src/jit/riscv64/Lowering-riscv64.cpp
@@ -170,11 +170,6 @@ void LIRGeneratorRiscv64::lowerMulI(MMul* mul, MDefinition* lhs,
}
void LIRGeneratorRiscv64::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()) {
@@ -213,22 +208,12 @@ void LIRGeneratorRiscv64::lowerDivI(MDiv* div) {
}
void LIRGeneratorRiscv64::lowerDivI64(MDiv* div) {
- if (div->isUnsigned()) {
- lowerUDivI64(div);
- return;
- }
-
auto* lir = new (alloc()) LDivOrModI64(useRegisterAtStart(div->lhs()),
useRegisterAtStart(div->rhs()));
defineInt64(lir, div);
}
void LIRGeneratorRiscv64::lowerModI(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUMod(mod);
- return;
- }
-
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->toInt32();
int32_t shift = FloorLog2(rhs);
@@ -268,11 +253,6 @@ void LIRGeneratorRiscv64::lowerModI(MMod* mod) {
}
void LIRGeneratorRiscv64::lowerModI64(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUModI64(mod);
- return;
- }
-
auto* lir = new (alloc()) LDivOrModI64(useRegisterAtStart(mod->lhs()),
useRegisterAtStart(mod->rhs()));
defineInt64(lir, mod);
diff --git a/js/src/jit/wasm32/Lowering-wasm32.h b/js/src/jit/wasm32/Lowering-wasm32.h
@@ -85,6 +85,8 @@ class LIRGeneratorWasm32 : public LIRGeneratorShared {
void lowerMulI(MMul*, MDefinition*, MDefinition*) { MOZ_CRASH(); }
void lowerUDiv(MDiv*) { MOZ_CRASH(); }
void lowerUMod(MMod*) { MOZ_CRASH(); }
+ void lowerUDivI64(MDiv*) { MOZ_CRASH(); }
+ void lowerUModI64(MMod*) { MOZ_CRASH(); }
void lowerWasmSelectI(MWasmSelect* select) { MOZ_CRASH(); }
void lowerWasmSelectI64(MWasmSelect* select) { MOZ_CRASH(); }
void lowerWasmCompareAndSelect(MWasmSelect* ins, MDefinition* lhs,
diff --git a/js/src/jit/x64/Lowering-x64.cpp b/js/src/jit/x64/Lowering-x64.cpp
@@ -526,11 +526,6 @@ void LIRGenerator::visitSubstr(MSubstr* ins) {
}
void LIRGeneratorX64::lowerDivI64(MDiv* div) {
- if (div->isUnsigned()) {
- lowerUDivI64(div);
- return;
- }
-
LDivOrModI64* lir = new (alloc()) LDivOrModI64(
useRegister(div->lhs()), useRegister(div->rhs()), tempFixed(rdx));
defineInt64Fixed(lir, div, LInt64Allocation(LAllocation(AnyRegister(rax))));
@@ -541,11 +536,6 @@ void LIRGeneratorX64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) {
}
void LIRGeneratorX64::lowerModI64(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUModI64(mod);
- return;
- }
-
LDivOrModI64* lir = new (alloc()) LDivOrModI64(
useRegister(mod->lhs()), useRegister(mod->rhs()), tempFixed(rax));
defineInt64Fixed(lir, mod, LInt64Allocation(LAllocation(AnyRegister(rdx))));
diff --git a/js/src/jit/x86-shared/Lowering-x86-shared.cpp b/js/src/jit/x86-shared/Lowering-x86-shared.cpp
@@ -169,11 +169,6 @@ void LIRGeneratorX86Shared::lowerMulI(MMul* mul, MDefinition* lhs,
}
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()) {
@@ -225,11 +220,6 @@ void LIRGeneratorX86Shared::lowerDivI(MDiv* div) {
}
void LIRGeneratorX86Shared::lowerModI(MMod* mod) {
- if (mod->isUnsigned()) {
- lowerUMod(mod);
- return;
- }
-
if (mod->rhs()->isConstant()) {
int32_t rhs = mod->rhs()->toConstant()->toInt32();
int32_t shift = FloorLog2(Abs(rhs));