[llvm] 266ffd7 - [InstrProf] Fix warning about converting double to float
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 6 12:38:43 PDT 2023
Author: Ellis Hoag
Date: 2023-06-06T12:36:49-07:00
New Revision: 266ffd7afff9f20e21a70fde06a164a2801bbf93
URL: https://github.com/llvm/llvm-project/commit/266ffd7afff9f20e21a70fde06a164a2801bbf93
DIFF: https://github.com/llvm/llvm-project/commit/266ffd7afff9f20e21a70fde06a164a2801bbf93.diff
LOG: [InstrProf] Fix warning about converting double to float
In https://reviews.llvm.org/D147812 I introduced the class
`BalancedPartitioning` and it seemed to trigger a warning in flang
```
C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\include\llvm/Support/BalancedPartitioning.h(89): warning C4305: 'initializing': truncation from 'double' to 'float'
```
For good measure, I converted all double literals to floats. This should
be a NFC.
Added:
Modified:
llvm/include/llvm/Support/BalancedPartitioning.h
llvm/lib/Support/BalancedPartitioning.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/BalancedPartitioning.h b/llvm/include/llvm/Support/BalancedPartitioning.h
index 0baf682387445..1677fb9e427d7 100644
--- a/llvm/include/llvm/Support/BalancedPartitioning.h
+++ b/llvm/include/llvm/Support/BalancedPartitioning.h
@@ -86,7 +86,7 @@ struct BalancedPartitioningConfig {
unsigned IterationsPerSplit = 40;
/// The probability for a vertex to skip a move from its current bucket to
/// another bucket; it often helps to escape from a local optima
- float SkipProbability = 0.1;
+ float SkipProbability = 0.1f;
/// Recursive subtasks up to the given depth are added to the queue and
/// distributed among threads by ThreadPool; all subsequent calls are executed
/// on the same thread
diff --git a/llvm/lib/Support/BalancedPartitioning.cpp b/llvm/lib/Support/BalancedPartitioning.cpp
index a982bb157ab82..324feeade089f 100644
--- a/llvm/lib/Support/BalancedPartitioning.cpp
+++ b/llvm/lib/Support/BalancedPartitioning.cpp
@@ -211,8 +211,8 @@ unsigned BalancedPartitioning::runIteration(const FunctionNodeRange Nodes,
unsigned R = Signature.RightCount;
assert((L > 0 || R > 0) && "incorrect signature");
float Cost = logCost(L, R);
- Signature.CachedGainLR = 0;
- Signature.CachedGainRL = 0;
+ Signature.CachedGainLR = 0.f;
+ Signature.CachedGainRL = 0.f;
if (L > 0)
Signature.CachedGainLR = Cost - logCost(L - 1, R + 1);
if (R > 0)
@@ -247,7 +247,7 @@ unsigned BalancedPartitioning::runIteration(const FunctionNodeRange Nodes,
auto &[LeftGain, LeftNode] = LeftPair;
auto &[RightGain, RightNode] = RightPair;
// Stop when the gain is no longer beneficial
- if (LeftGain + RightGain <= 0.0)
+ if (LeftGain + RightGain <= 0.f)
break;
// Try to exchange the nodes between buckets
if (moveFunctionNode(*LeftNode, LeftBucket, RightBucket, Signatures, RNG))
@@ -264,7 +264,7 @@ bool BalancedPartitioning::moveFunctionNode(BPFunctionNode &N,
SignaturesT &Signatures,
std::mt19937 &RNG) const {
// Sometimes we skip the move. This helps to escape local optima
- if (std::uniform_real_distribution<float>(0.0, 1.0)(RNG) <=
+ if (std::uniform_real_distribution<float>(0.f, 1.f)(RNG) <=
Config.SkipProbability)
return false;
@@ -309,7 +309,7 @@ void BalancedPartitioning::split(const FunctionNodeRange Nodes,
float BalancedPartitioning::moveGain(const BPFunctionNode &N,
bool FromLeftToRight,
const SignaturesT &Signatures) {
- float Gain = 0;
+ float Gain = 0.f;
for (auto &UN : N.UtilityNodes)
Gain += (FromLeftToRight ? Signatures[UN].CachedGainLR
: Signatures[UN].CachedGainRL);
More information about the llvm-commits
mailing list