[llvm] [AMDGPU][SplitModule] Fix potential divide by zero (PR #117602)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 10:18:11 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Fraser Cormack (frasercrmck)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/117602.diff
1 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp (+2-1)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/117602
More information about the llvm-commits
mailing list