[llvm] [AMDGPU][SplitModule] Fix a couple of issues (PR #117586)
Fraser Cormack via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 10:02:48 PST 2024
https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/117586
A static analysis tool found that ModuleCost could be zero, so would perform divide by zero when being printed. Perhaps this is unreachable in practice, but the fix is straightforward enough and unlikely to be a performance concern.
The same tool warned that a division was always being performed in integer division, so was either 0.0 or 1.0. This doesn't seem intentional, so has been fixed to return a true ratio using floating-point division. This has a knock-on effect on how a test was splitting modules.
>From 9f271dd2904a97b593602ac5e52964b343bcfc3e Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Mon, 25 Nov 2024 17:56:50 +0000
Subject: [PATCH] [AMDGPU][SplitModule] Fix a couple of issues
A static analysis tool found that ModuleCost could be zero, so would
perform divide by zero when being printed. Perhaps this is unreachable
in practice, but the fix is straightforward enough and unlikely to be a
performance concern.
The same tool warned that a division was always being performed in
integer division, so was either 0.0 or 1.0. This doesn't seem
intentional, so has been fixed to return a true ratio using
floating-point division. This has a knock-on effect on how a test was
splitting modules.
---
llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp | 5 +++--
.../llvm-split/AMDGPU/large-kernels-merging.ll | 13 +++++++------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
index 5d7aff1c5092cc..a7db7cdb890051 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -149,7 +149,8 @@ static constexpr unsigned InvalidPID = -1;
/// \param Dem denominator
/// \returns a printable object to print (Num/Dem) using "%0.2f".
static auto formatRatioOf(CostType Num, CostType Dem) {
- return format("%0.2f", (static_cast<double>(Num) / Dem) * 100);
+ CostType DemOr1 = Dem ? Dem : 1;
+ return format("%0.2f", (static_cast<double>(Num) / DemOr1) * 100);
}
/// Checks whether a given function is non-copyable.
@@ -1101,7 +1102,7 @@ void RecursiveSearchSplitting::pickPartition(unsigned Depth, unsigned Idx,
// Check if the amount of code in common makes it worth it.
assert(SimilarDepsCost && Entry.CostExcludingGraphEntryPoints);
const double Ratio =
- SimilarDepsCost / Entry.CostExcludingGraphEntryPoints;
+ (double)SimilarDepsCost / Entry.CostExcludingGraphEntryPoints;
assert(Ratio >= 0.0 && Ratio <= 1.0);
if (LargeFnOverlapForMerge > Ratio) {
// For debug, just print "L", so we'll see "L3=P3" for instance, which
diff --git a/llvm/test/tools/llvm-split/AMDGPU/large-kernels-merging.ll b/llvm/test/tools/llvm-split/AMDGPU/large-kernels-merging.ll
index 807fb2e5f33cea..2810e9853bebe3 100644
--- a/llvm/test/tools/llvm-split/AMDGPU/large-kernels-merging.ll
+++ b/llvm/test/tools/llvm-split/AMDGPU/large-kernels-merging.ll
@@ -15,19 +15,20 @@
; Also check w/o large kernels processing to verify they are indeed handled
; differently.
-; P0 is empty
-; CHECK0: declare
+; CHECK0: define internal void @HelperC()
+; CHECK0: define amdgpu_kernel void @C
-; CHECK1: define internal void @HelperC()
-; CHECK1: define amdgpu_kernel void @C
+; CHECK1: define internal void @large2()
+; CHECK1: define internal void @large1()
+; CHECK1: define internal void @large0()
+; CHECK1: define internal void @HelperB()
+; CHECK1: define amdgpu_kernel void @B
; CHECK2: define internal void @large2()
; CHECK2: define internal void @large1()
; CHECK2: define internal void @large0()
; CHECK2: define internal void @HelperA()
-; CHECK2: define internal void @HelperB()
; CHECK2: define amdgpu_kernel void @A
-; CHECK2: define amdgpu_kernel void @B
; NOLARGEKERNELS-CHECK0: define internal void @HelperC()
; NOLARGEKERNELS-CHECK0: define amdgpu_kernel void @C
More information about the llvm-commits
mailing list