diff options
author | Gilles Grospellier <gilles.grospellier@cea.fr> | 2022-10-01 19:32:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-01 19:32:12 +0300 |
commit | fe335593152fd96bbfd970541a89add763c887a4 (patch) | |
tree | 53b9cf0bd220e13556f1d11626b14d5c2d561486 | |
parent | 72ac50cef091a46d9c02b43f6f4f1785011afe4a (diff) |
[JIT] Fix potential division by zero in fgopt.cpp (#76424)
Division by zero in C++ is undefined behavior on some architecture and
should be avoided.
Co-authored-by: Andy Ayers <andya@microsoft.com>
-rw-r--r-- | src/coreclr/jit/fgopt.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index bbd294684de..ab50d166a7a 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -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; } |