Skip to content

Commit 6148922

Browse files
committed
Apply some small reviewer suggestions
1 parent 2791a1c commit 6148922

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

llvm/include/llvm/Transforms/Utils/LoopUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ LLVM_ABI bool addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
355355
/// TODO: Eventually, once all passes have migrated away from setting branch
356356
/// weights to indicate estimated trip counts, this function will drop the
357357
/// \p EstimatedLoopInvocationWeight parameter.
358+
///
359+
/// TODO: There are also passes that currently do not consider estimated trip
360+
/// counts at all but that, for example, affect whether trip counts can be
361+
/// estimated from branch weights. Once all such passes have been adjusted to
362+
/// update this metadata, this function might stop estimating trip counts from
363+
/// branch weights and instead simply get the \c llvm.loop_estimated_trip_count
364+
/// metadata. See also the \c llvm.loop.estimated_trip_count entry in
365+
/// \c LangRef.rst.
358366
LLVM_ABI std::optional<unsigned>
359367
getLoopEstimatedTripCount(Loop *L,
360368
unsigned *EstimatedLoopInvocationWeight = nullptr,

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ bool llvm::addStringMetadataToLoop(Loop *TheLoop, const char *StringMD,
226226
if (NumOps == 1 || NumOps == 2) {
227227
MDString *S = dyn_cast<MDString>(Node->getOperand(0));
228228
if (S && S->getString() == StringMD) {
229-
// If it is already in place, do nothing.
229+
// If the metadata and any value are already as specified, do nothing.
230230
if (NumOps == 2 && V) {
231231
ConstantInt *IntMD =
232232
mdconst::extract_or_null<ConstantInt>(Node->getOperand(1));
@@ -879,7 +879,7 @@ std::optional<unsigned> llvm::getLoopEstimatedTripCount(
879879
// EstimatedLoopInvocationWeight parameter.
880880
if (EstimatedLoopInvocationWeight) {
881881
if (BranchInst *ExitingBranch = getExpectedExitLoopLatchBranch(L)) {
882-
uint64_t LoopWeight, ExitWeight;
882+
uint64_t LoopWeight = 0, ExitWeight = 0; // Inits expected to be unused.
883883
if (!extractBranchWeights(*ExitingBranch, LoopWeight, ExitWeight))
884884
return std::nullopt;
885885
if (L->contains(ExitingBranch->getSuccessor(1)))
@@ -951,7 +951,7 @@ bool llvm::setLoopEstimatedTripCount(
951951
unsigned LatchExitWeight = 0;
952952
unsigned BackedgeTakenWeight = 0;
953953

954-
if (*EstimatedTripCount > 0) {
954+
if (*EstimatedTripCount != 0) {
955955
LatchExitWeight = *EstimatedloopInvocationWeight;
956956
BackedgeTakenWeight = (*EstimatedTripCount - 1) * LatchExitWeight;
957957
}

0 commit comments

Comments
 (0)