Skip to content

Commit fd8e478

Browse files
frasercrmckPierre-vh
authored andcommitted
[AMDGPU][SplitModule] Fix potential divide by zero (llvm#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. Change-Id: Ide6da3ec27e1d104905aba6534c3960982b6e176
1 parent a399743 commit fd8e478

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)