[llvm] [AMDGPU][llvm-split] Fix another division by zero (PR #104421)
Fraser Cormack via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 02:15:17 PDT 2024
https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/104421
Somehow I missed this in #98888. It requires a log file, or the debug flag to be passed.
>From 47eb0feade658341c13330adf52e6e93ca9dd37d Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Thu, 15 Aug 2024 10:13:55 +0100
Subject: [PATCH] [AMDGPU][llvm-split] Fix another division by zero
Somehow I missed this in #98888. It requires a log file, or the debug
flag to be passed.
---
llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp | 3 ++-
.../tools/llvm-split/AMDGPU/declarations-debug.ll | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/tools/llvm-split/AMDGPU/declarations-debug.ll
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