Skip to content

Commit

Permalink
[JIT] Fix potential division by zero in fgopt.cpp (#76424)
Browse files Browse the repository at this point in the history
Division by zero in C++ is undefined behavior on some architecture and
should be avoided.

Co-authored-by: Andy Ayers <andya@microsoft.com>
  • Loading branch information
grospelliergilles and AndyAyersMS authored Oct 1, 2022
1 parent 72ac50c commit fe33559
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4988,10 +4988,10 @@ bool Compiler::fgReorderBlocks(bool useProfile)
double notTakenCount =
((double)edgeToBlock->edgeWeightMin() + (double)edgeToBlock->edgeWeightMax()) / 2.0;
double totalCount = takenCount + notTakenCount;
double takenRatio = takenCount / totalCount;

// If the takenRatio is greater or equal to 51% then we will reverse the branch
if (takenRatio < 0.51)
// If the takenRatio (takenCount / totalCount) is greater or equal to 51% then we will reverse
// the branch
if (takenCount < (0.51 * totalCount))
{
reorderBlock = false;
}
Expand Down

0 comments on commit fe33559

Please sign in to comment.