Skip to content

Commit

Permalink
[RISC-V] Check DivideByZeroException before generating check for unsi…
Browse files Browse the repository at this point in the history
…gned 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
  • Loading branch information
tomeksowi authored Feb 22, 2024
1 parent 8dcb639 commit 24a9069
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/coreclr/jit/codegenriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,8 @@ void CodeGen::genCodeForDivMod(GenTreeOp* tree)
// Note that division by the constant 0 was already checked for above by the
// op2->IsIntegralConst(0) check

if (!divisorOp->IsCnsIntOrI())
if ((exceptions & ExceptionSetFlags::DivideByZeroException) != ExceptionSetFlags::None &&
!divisorOp->IsCnsIntOrI())
{
// divisorOp is not a constant, so it could be zero
genJumpToThrowHlpBlk_la(SCK_DIV_BY_ZERO, INS_beq, divisorReg);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsrariscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int LinearScan::BuildNode(GenTree* tree)
needTemp = true;
}

if (!needTemp && (tree->gtOper == GT_DIV || tree->gtOper == GT_MOD))
if (!needTemp && tree->OperIs(GT_DIV, GT_MOD))
{
if ((exceptions & ExceptionSetFlags::ArithmeticException) != ExceptionSetFlags::None)
needTemp = true;
Expand Down

0 comments on commit 24a9069

Please sign in to comment.