[llvm] 075f754 - [AMDGPU][llvm-split] Fix division by zero (#98888)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 07:06:41 PDT 2024
Author: Fraser Cormack
Date: 2024-07-15T15:06:37+01:00
New Revision: 075f7542f1b55695b871fb5d6359c2350af474f8
URL: https://github.com/llvm/llvm-project/commit/075f7542f1b55695b871fb5d6359c2350af474f8
DIFF: https://github.com/llvm/llvm-project/commit/075f7542f1b55695b871fb5d6359c2350af474f8.diff
LOG: [AMDGPU][llvm-split] Fix division by zero (#98888)
An empty module, or one containing only declarations, would result in a
division by a zero cost.
Added:
llvm/test/tools/llvm-split/AMDGPU/declarations.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 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