[llvm] [AMDGPU][llvm-split] Fix division by zero (PR #98888)
Fraser Cormack via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 04:42:06 PDT 2024
https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/98888
An empty module, or one containing only declarations, would result in a division by a zero cost.
>From f7d1a947df6f180a0fa83958f0934e901ed91ff6 Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Mon, 15 Jul 2024 12:40:48 +0100
Subject: [PATCH] [AMDGPU][llvm-split] Fix division by zero
An empty module, or one containing only declarations, would result in a
division by a zero cost.
---
llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp | 5 +++--
llvm/test/tools/llvm-split/AMDGPU/declarations.ll | 15 +++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/tools/llvm-split/AMDGPU/declarations.ll
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
index 3e5d83b8e3fb1..f75961f6eaa77 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -256,11 +256,12 @@ calculateFunctionCosts(SplitModuleLogger &SML, GetTTIFn GetTTI, Module &M,
}
CostType FnCost = (ModuleCost - KernelCost);
+ CostType ModuleCostOr1 = ModuleCost ? ModuleCost : 1;
SML << "=> Total Module Cost: " << ModuleCost << '\n'
<< " => KernelCost: " << KernelCost << " ("
- << format("%0.2f", (float(KernelCost) / ModuleCost) * 100) << "%)\n"
+ << format("%0.2f", (float(KernelCost) / ModuleCostOr1) * 100) << "%)\n"
<< " => FnsCost: " << FnCost << " ("
- << format("%0.2f", (float(FnCost) / ModuleCost) * 100) << "%)\n";
+ << format("%0.2f", (float(FnCost) / ModuleCostOr1) * 100) << "%)\n";
return ModuleCost;
}
diff --git a/llvm/test/tools/llvm-split/AMDGPU/declarations.ll b/llvm/test/tools/llvm-split/AMDGPU/declarations.ll
new file mode 100644
index 0000000000000..f579056e914aa
--- /dev/null
+++ b/llvm/test/tools/llvm-split/AMDGPU/declarations.ll
@@ -0,0 +1,15 @@
+; RUN: llvm-split -o %t %s -j 2 -mtriple amdgcn-amd-amdhsa
+; RUN: llvm-dis -o - %t0 | FileCheck --check-prefix=CHECK0 %s
+; RUN: llvm-dis -o - %t1 | FileCheck --check-prefix=CHECK1 %s
+
+; Check that all declarations are put into each partition.
+
+; CHECK0: declare void @A
+; CHECK0: declare void @B
+
+; CHECK1: declare void @A
+; CHECK1: declare void @B
+
+declare void @A()
+
+declare void @B()
More information about the llvm-commits
mailing list