[llvm] 345b331 - [AMDGPU][SplitModule] Fix unintentional integer division (#117586)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 02:18:56 PST 2024


Author: Fraser Cormack
Date: 2024-11-27T10:18:52Z
New Revision: 345b3319c8544a0124aed9602c31f8793228ab63

URL: https://github.com/llvm/llvm-project/commit/345b3319c8544a0124aed9602c31f8793228ab63
DIFF: https://github.com/llvm/llvm-project/commit/345b3319c8544a0124aed9602c31f8793228ab63.diff

LOG: [AMDGPU][SplitModule] Fix unintentional integer division (#117586)

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.

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 3b6c2cbe390ed2..3332ed9c006e54 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -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.


        


More information about the llvm-commits mailing list