[llvm] 2e9f3f3 - [AMDGPU][llvm-split] Fix another division by zero (#104421)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 04:54:31 PDT 2024


Author: Fraser Cormack
Date: 2024-08-15T12:54:26+01:00
New Revision: 2e9f3f3b842538b55552aa22fdc0bf1966637ca8

URL: https://github.com/llvm/llvm-project/commit/2e9f3f3b842538b55552aa22fdc0bf1966637ca8
DIFF: https://github.com/llvm/llvm-project/commit/2e9f3f3b842538b55552aa22fdc0bf1966637ca8.diff

LOG: [AMDGPU][llvm-split] Fix another division by zero (#104421)

Somehow I missed this in #98888. It requires a log file, or the debug
flag to be passed.

Added: 
    llvm/test/tools/llvm-split/AMDGPU/declarations-debug.ll

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 bd0f0e048809bc..df084cf41c4783 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -568,12 +568,13 @@ doPartitioning(SplitModuleLogger &SML, Module &M, unsigned NumParts,
   }
 
   if (SML) {
+    CostType ModuleCostOr1 = ModuleCost ? ModuleCost : 1;
     for (const auto &[Idx, Part] : enumerate(Partitions)) {
       CostType Cost = 0;
       for (auto *Fn : Part)
         Cost += FnCosts.at(Fn);
       SML << "P" << Idx << " has a total cost of " << Cost << " ("
-          << format("%0.2f", (float(Cost) / ModuleCost) * 100)
+          << format("%0.2f", (float(Cost) / ModuleCostOr1) * 100)
           << "% of source module)\n";
     }
 

diff  --git a/llvm/test/tools/llvm-split/AMDGPU/declarations-debug.ll b/llvm/test/tools/llvm-split/AMDGPU/declarations-debug.ll
new file mode 100644
index 00000000000000..66b89659f5d4f9
--- /dev/null
+++ b/llvm/test/tools/llvm-split/AMDGPU/declarations-debug.ll
@@ -0,0 +1,12 @@
+; RUN: llvm-split -o %t %s -j 2 -mtriple amdgcn-amd-amdhsa --debug
+
+; REQUIRES: asserts
+
+; CHECK: --Partitioning Starts--
+; CHECK: P0 has a total cost of 0 (0.00% of source module)
+; CHECK: P1 has a total cost of 0 (0.00% of source module)
+; CHECK: --Partitioning Done--
+
+declare void @A()
+
+declare void @B()


        


More information about the llvm-commits mailing list