commit 412b9a4602fd9792832b093fc42784134ba97756
parent c9aa1d1a1c9a622658cec3ca2c4b1d29b78eb6d5
Author: André Bargull <andre.bargull@gmail.com>
Date: Fri, 24 Oct 2025 14:58:54 +0000
Bug 1996085 - Part 1: Call lowerForALU for LNegI. r=spidermonkey-reviewers,jandem
We can directly call `lowerForALU` instead of defining `lowerNegI` for each
architecture.
Differential Revision: https://phabricator.services.mozilla.com/D269840
Diffstat:
16 files changed, 14 insertions(+), 44 deletions(-)
diff --git a/js/src/jit/LIROps.yaml b/js/src/jit/LIROps.yaml
@@ -1112,6 +1112,7 @@
result_type: WordSized
operands:
input: WordSized
+ defer_init: true
# Negative of an int64
- name: NegI64
diff --git a/js/src/jit/Lowering.cpp b/js/src/jit/Lowering.cpp
@@ -2297,19 +2297,19 @@ void LIRGenerator::visitSub(MSub* ins) {
if (ins->type() == MIRType::Int32) {
MOZ_ASSERT(lhs->type() == MIRType::Int32);
- LSubI* lir = new (alloc()) LSubI;
- if (ins->fallible()) {
- assignSnapshot(lir, ins->bailoutKind());
- }
-
// If our LHS is a constant 0 and we don't have to worry about results that
// can't be represented as an int32, we can optimize to an LNegI.
if (!ins->fallible() && lhs->isConstant() &&
lhs->toConstant()->toInt32() == 0) {
- lowerNegI(ins, rhs);
+ lowerForALU(new (alloc()) LNegI, ins, rhs);
return;
}
+ LSubI* lir = new (alloc()) LSubI;
+ if (ins->fallible()) {
+ assignSnapshot(lir, ins->bailoutKind());
+ }
+
lowerForALU(lir, ins, lhs, rhs);
MaybeSetRecoversInput(ins, lir);
return;
@@ -2366,7 +2366,7 @@ void LIRGenerator::visitMul(MMul* ins) {
// can't be represented as an int32, we can optimize to an LNegI.
if (!ins->fallible() && rhs->isConstant() &&
rhs->toConstant()->toInt32() == -1) {
- lowerNegI(ins, lhs);
+ lowerForALU(new (alloc()) LNegI, ins, lhs);
return;
}
diff --git a/js/src/jit/arm/Lowering-arm.cpp b/js/src/jit/arm/Lowering-arm.cpp
@@ -352,10 +352,6 @@ void LIRGeneratorARM::lowerDivI(MDiv* div) {
defineReturn(lir, div);
}
-void LIRGeneratorARM::lowerNegI(MInstruction* ins, MDefinition* input) {
- define(new (alloc()) LNegI(useRegisterAtStart(input)), ins);
-}
-
void LIRGeneratorARM::lowerNegI64(MInstruction* ins, MDefinition* input) {
// Reuse the input. Define + use-at-start would create risk that the output
// uses the same register pair as the input but in reverse order. Reusing
@@ -586,7 +582,7 @@ void LIRGeneratorARM::lowerBigIntPtrMod(MBigIntPtrMod* ins) {
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) {
if (ins->type() == MIRType::Int32) {
- define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins);
+ lowerForALU(new (alloc()) LNegI, ins, ins->input());
} else if (ins->type() == MIRType::Float32) {
define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins);
} else {
diff --git a/js/src/jit/arm/Lowering-arm.h b/js/src/jit/arm/Lowering-arm.h
@@ -78,7 +78,6 @@ class LIRGeneratorARM : public LIRGeneratorShared {
void lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod);
void lowerUDivI64(MDiv* div);
void lowerUModI64(MMod* mod);
- void lowerNegI(MInstruction* ins, MDefinition* input);
void lowerNegI64(MInstruction* ins, MDefinition* input);
void lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs);
void lowerUDiv(MDiv* div);
diff --git a/js/src/jit/arm64/Lowering-arm64.cpp b/js/src/jit/arm64/Lowering-arm64.cpp
@@ -240,10 +240,6 @@ void LIRGeneratorARM64::lowerDivI(MDiv* div) {
define(lir, div);
}
-void LIRGeneratorARM64::lowerNegI(MInstruction* ins, MDefinition* input) {
- define(new (alloc()) LNegI(useRegisterAtStart(input)), ins);
-}
-
void LIRGeneratorARM64::lowerNegI64(MInstruction* ins, MDefinition* input) {
defineInt64(new (alloc()) LNegI64(useInt64RegisterAtStart(input)), ins);
}
@@ -518,7 +514,7 @@ bool LIRGeneratorARM64::canEmitWasmReduceSimd128AtUses(
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) {
switch (ins->type()) {
case MIRType::Int32:
- define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins);
+ lowerForALU(new (alloc()) LNegI, ins, ins->input());
break;
case MIRType::Float32:
define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins);
diff --git a/js/src/jit/arm64/Lowering-arm64.h b/js/src/jit/arm64/Lowering-arm64.h
@@ -85,7 +85,6 @@ class LIRGeneratorARM64 : public LIRGeneratorShared {
void lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod);
void lowerUDivI64(MDiv* div);
void lowerUModI64(MMod* mod);
- void lowerNegI(MInstruction* ins, MDefinition* input);
void lowerNegI64(MInstruction* ins, MDefinition* input);
void lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs);
void lowerUDiv(MDiv* div);
diff --git a/js/src/jit/loong64/Lowering-loong64.cpp b/js/src/jit/loong64/Lowering-loong64.cpp
@@ -150,9 +150,6 @@ void LIRGeneratorLOONG64::defineInt64Phi(MPhi* phi, size_t lirIndex) {
defineTypedPhi(phi, lirIndex);
}
-void LIRGeneratorLOONG64::lowerNegI(MInstruction* ins, MDefinition* input) {
- define(new (alloc()) LNegI(useRegisterAtStart(input)), ins);
-}
void LIRGeneratorLOONG64::lowerNegI64(MInstruction* ins, MDefinition* input) {
defineInt64ReuseInput(new (alloc()) LNegI64(useInt64RegisterAtStart(input)),
ins, 0);
@@ -833,7 +830,7 @@ void LIRGenerator::visitWasmStore(MWasmStore* ins) {
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) {
if (ins->type() == MIRType::Int32) {
- define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins);
+ lowerForALU(new (alloc()) LNegI, ins, ins->input());
} else if (ins->type() == MIRType::Float32) {
define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins);
} else {
diff --git a/js/src/jit/loong64/Lowering-loong64.h b/js/src/jit/loong64/Lowering-loong64.h
@@ -62,7 +62,6 @@ class LIRGeneratorLOONG64 : public LIRGeneratorShared {
void lowerInt64PhiInput(MPhi*, uint32_t, LBlock*, size_t);
void defineInt64Phi(MPhi*, size_t);
- void lowerNegI(MInstruction* ins, MDefinition* input);
void lowerNegI64(MInstruction* ins, MDefinition* input);
void lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs);
void lowerDivI(MDiv* div);
diff --git a/js/src/jit/mips-shared/Lowering-mips-shared.cpp b/js/src/jit/mips-shared/Lowering-mips-shared.cpp
@@ -172,10 +172,6 @@ void LIRGeneratorMIPSShared::lowerDivI(MDiv* div) {
define(lir, div);
}
-void LIRGeneratorMIPSShared::lowerNegI(MInstruction* ins, MDefinition* input) {
- define(new (alloc()) LNegI(useRegisterAtStart(input)), ins);
-}
-
void LIRGeneratorMIPSShared::lowerNegI64(MInstruction* ins,
MDefinition* input) {
defineInt64ReuseInput(new (alloc()) LNegI64(useInt64RegisterAtStart(input)),
@@ -320,7 +316,7 @@ void LIRGeneratorMIPSShared::lowerBigIntPtrMod(MBigIntPtrMod* ins) {
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) {
if (ins->type() == MIRType::Int32) {
- define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins);
+ lowerForALU(new (alloc()) LNegI, ins, ins->input());
} else if (ins->type() == MIRType::Float32) {
define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins);
} else {
diff --git a/js/src/jit/mips-shared/Lowering-mips-shared.h b/js/src/jit/mips-shared/Lowering-mips-shared.h
@@ -56,7 +56,6 @@ class LIRGeneratorMIPSShared : public LIRGeneratorShared {
void lowerWasmBuiltinTruncateToInt32(MWasmBuiltinTruncateToInt32* ins);
void lowerDivI(MDiv* div);
void lowerModI(MMod* mod);
- void lowerNegI(MInstruction* ins, MDefinition* input);
void lowerNegI64(MInstruction* ins, MDefinition* input);
void lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs);
void lowerUDiv(MDiv* div);
diff --git a/js/src/jit/none/Lowering-none.h b/js/src/jit/none/Lowering-none.h
@@ -83,7 +83,6 @@ class LIRGeneratorNone : public LIRGeneratorShared {
void lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) { MOZ_CRASH(); }
void lowerModI64(MMod*) { MOZ_CRASH(); }
void lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) { MOZ_CRASH(); }
- void lowerNegI(MInstruction*, MDefinition*) { MOZ_CRASH(); }
void lowerNegI64(MInstruction*, MDefinition*) { MOZ_CRASH(); }
void lowerMulI(MMul*, MDefinition*, MDefinition*) { MOZ_CRASH(); }
void lowerUDiv(MDiv*) { MOZ_CRASH(); }
diff --git a/js/src/jit/riscv64/Lowering-riscv64.cpp b/js/src/jit/riscv64/Lowering-riscv64.cpp
@@ -150,9 +150,6 @@ void LIRGeneratorRiscv64::defineInt64Phi(MPhi* phi, size_t lirIndex) {
defineTypedPhi(phi, lirIndex);
}
-void LIRGeneratorRiscv64::lowerNegI(MInstruction* ins, MDefinition* input) {
- define(new (alloc()) LNegI(useRegisterAtStart(input)), ins);
-}
void LIRGeneratorRiscv64::lowerNegI64(MInstruction* ins, MDefinition* input) {
defineInt64ReuseInput(new (alloc()) LNegI64(useInt64RegisterAtStart(input)),
ins, 0);
@@ -834,7 +831,7 @@ void LIRGenerator::visitWasmStore(MWasmStore* ins) {
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) {
if (ins->type() == MIRType::Int32) {
- define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins);
+ lowerForALU(new (alloc()) LNegI, ins, ins->input());
} else if (ins->type() == MIRType::Float32) {
define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins);
} else {
diff --git a/js/src/jit/riscv64/Lowering-riscv64.h b/js/src/jit/riscv64/Lowering-riscv64.h
@@ -62,7 +62,6 @@ class LIRGeneratorRiscv64 : public LIRGeneratorShared {
void lowerInt64PhiInput(MPhi*, uint32_t, LBlock*, size_t);
void defineInt64Phi(MPhi*, size_t);
- void lowerNegI(MInstruction* ins, MDefinition* input);
void lowerNegI64(MInstruction* ins, MDefinition* input);
void lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs);
void lowerDivI(MDiv* div);
diff --git a/js/src/jit/wasm32/Lowering-wasm32.h b/js/src/jit/wasm32/Lowering-wasm32.h
@@ -82,7 +82,6 @@ class LIRGeneratorWasm32 : public LIRGeneratorShared {
void lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) { MOZ_CRASH(); }
void lowerModI64(MMod*) { MOZ_CRASH(); }
void lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) { MOZ_CRASH(); }
- void lowerNegI(MInstruction*, MDefinition*) { MOZ_CRASH(); }
void lowerNegI64(MInstruction*, MDefinition*) { MOZ_CRASH(); }
void lowerMulI(MMul*, MDefinition*, MDefinition*) { MOZ_CRASH(); }
void lowerUDiv(MDiv*) { MOZ_CRASH(); }
diff --git a/js/src/jit/x86-shared/Lowering-x86-shared.cpp b/js/src/jit/x86-shared/Lowering-x86-shared.cpp
@@ -168,10 +168,6 @@ void LIRGeneratorX86Shared::lowerForFPU(LInstructionHelper<1, 2, 0>* ins,
}
}
-void LIRGeneratorX86Shared::lowerNegI(MInstruction* ins, MDefinition* input) {
- defineReuseInput(new (alloc()) LNegI(useRegisterAtStart(input)), ins, 0);
-}
-
void LIRGeneratorX86Shared::lowerNegI64(MInstruction* ins, MDefinition* input) {
defineInt64ReuseInput(new (alloc()) LNegI64(useInt64RegisterAtStart(input)),
ins, 0);
@@ -293,8 +289,7 @@ void LIRGeneratorX86Shared::lowerModI(MMod* mod) {
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) {
switch (ins->type()) {
case MIRType::Int32:
- defineReuseInput(new (alloc()) LNegI(useRegisterAtStart(ins->input())),
- ins, 0);
+ lowerForALU(new (alloc()) LNegI, ins, ins->input());
break;
case MIRType::Float32:
defineReuseInput(new (alloc()) LNegF(useRegisterAtStart(ins->input())),
diff --git a/js/src/jit/x86-shared/Lowering-x86-shared.h b/js/src/jit/x86-shared/Lowering-x86-shared.h
@@ -38,7 +38,6 @@ class LIRGeneratorX86Shared : public LIRGeneratorShared {
void lowerForFPU(LInstructionHelper<1, 2, 0>* ins, MDefinition* mir,
MDefinition* lhs, MDefinition* rhs);
- void lowerNegI(MInstruction* ins, MDefinition* input);
void lowerNegI64(MInstruction* ins, MDefinition* input);
void lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs);
void lowerDivI(MDiv* div);