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

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 02:15:51 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Fraser Cormack (frasercrmck)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/104421.diff


2 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp (+2-1) 
- (added) llvm/test/tools/llvm-split/AMDGPU/declarations-debug.ll (+12) 


``````````diff
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()

``````````

</details>


https://github.com/llvm/llvm-project/pull/104421


More information about the llvm-commits mailing list