Skip to content

Commit

Permalink
[AMDGPU][SplitModule] Fix unintentional integer division (llvm#117586)
Browse files Browse the repository at this point in the history
A static analysis tool warned that a division was always being performed
in integer division, so was either 0.0 or 1.0.

This doesn't seem intentional, so has been fixed to return a true ratio
using floating-point division. This in turn showed a bug where a
comparison against this ratio was incorrect.
  • Loading branch information
frasercrmck authored Nov 27, 2024
1 parent 712ef7d commit 345b331
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,10 @@ void RecursiveSearchSplitting::pickPartition(unsigned Depth, unsigned Idx,
if (Entry.CostExcludingGraphEntryPoints > LargeClusterThreshold) {
// Check if the amount of code in common makes it worth it.
assert(SimilarDepsCost && Entry.CostExcludingGraphEntryPoints);
const double Ratio =
SimilarDepsCost / Entry.CostExcludingGraphEntryPoints;
const double Ratio = static_cast<double>(SimilarDepsCost) /
Entry.CostExcludingGraphEntryPoints;
assert(Ratio >= 0.0 && Ratio <= 1.0);
if (LargeFnOverlapForMerge > Ratio) {
if (Ratio > LargeFnOverlapForMerge) {
// For debug, just print "L", so we'll see "L3=P3" for instance, which
// will mean we reached max depth and chose P3 based on this
// heuristic.
Expand Down

0 comments on commit 345b331

Please sign in to comment.