Skip to content

Commit 3414993

Browse files
authored
[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.
1 parent 36b1811 commit 3414993

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ static constexpr unsigned InvalidPID = -1;
149149
/// \param Dem denominator
150150
/// \returns a printable object to print (Num/Dem) using "%0.2f".
151151
static auto formatRatioOf(CostType Num, CostType Dem) {
152-
return format("%0.2f", (static_cast<double>(Num) / Dem) * 100);
152+
CostType DemOr1 = Dem ? Dem : 1;
153+
return format("%0.2f", (static_cast<double>(Num) / DemOr1) * 100);
153154
}
154155

155156
/// Checks whether a given function is non-copyable.

0 commit comments

Comments
 (0)