Skip to content

Commit 24a9069

Browse files
authored
[RISC-V] Check DivideByZeroException before generating check for unsigned div/mod (#98648)
* Generate check for unsigned divide by zero only when ExceptionSetFlags::DivideByZeroException is present Not doing so caused JITting on FullOpts fail on assert(add->acdUsed) in genJumpToThrowHlpBlk_la when the DivByZero check was optimized out as a result of #98113 * Change check for GT_DIV or GT_MOD in LSRA to look the same as CodeGen::genCodeForDivMod
1 parent 8dcb639 commit 24a9069

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/coreclr/jit/codegenriscv64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,8 @@ void CodeGen::genCodeForDivMod(GenTreeOp* tree)
24882488
// Note that division by the constant 0 was already checked for above by the
24892489
// op2->IsIntegralConst(0) check
24902490

2491-
if (!divisorOp->IsCnsIntOrI())
2491+
if ((exceptions & ExceptionSetFlags::DivideByZeroException) != ExceptionSetFlags::None &&
2492+
!divisorOp->IsCnsIntOrI())
24922493
{
24932494
// divisorOp is not a constant, so it could be zero
24942495
genJumpToThrowHlpBlk_la(SCK_DIV_BY_ZERO, INS_beq, divisorReg);

src/coreclr/jit/lsrariscv64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ int LinearScan::BuildNode(GenTree* tree)
309309
needTemp = true;
310310
}
311311

312-
if (!needTemp && (tree->gtOper == GT_DIV || tree->gtOper == GT_MOD))
312+
if (!needTemp && tree->OperIs(GT_DIV, GT_MOD))
313313
{
314314
if ((exceptions & ExceptionSetFlags::ArithmeticException) != ExceptionSetFlags::None)
315315
needTemp = true;

0 commit comments

Comments
 (0)