[llvm] 3414993 - [AMDGPU][SplitModule] Fix potential divide by zero (#117602)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 02:05:12 PST 2024


Author: Fraser Cormack
Date: 2024-11-26T10:05:09Z
New Revision: 3414993eaffcfa2cb4ff723c8468434d56dff213

URL: https://github.com/llvm/llvm-project/commit/3414993eaffcfa2cb4ff723c8468434d56dff213
DIFF: https://github.com/llvm/llvm-project/commit/3414993eaffcfa2cb4ff723c8468434d56dff213.diff

LOG: [AMDGPU][SplitModule] Fix potential divide by zero (#117602)

A static analysis tool found that ModuleCost could be zero, so would
perform divide by zero when being printed. Perhaps this is unreachable
in practice, but the fix is straightforward enough and unlikely to be a
performance concern.

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
index 5d7aff1c5092cc..3b6c2cbe390ed2 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -149,7 +149,8 @@ static constexpr unsigned InvalidPID = -1;
 /// \param Dem denominator
 /// \returns a printable object to print (Num/Dem) using "%0.2f".
 static auto formatRatioOf(CostType Num, CostType Dem) {
-  return format("%0.2f", (static_cast<double>(Num) / Dem) * 100);
+  CostType DemOr1 = Dem ? Dem : 1;
+  return format("%0.2f", (static_cast<double>(Num) / DemOr1) * 100);
 }
 
 /// Checks whether a given function is non-copyable.


        


More information about the llvm-commits mailing list