Skip to content

Commit 7ed4b7e

Browse files
committed
[SCEVExpander] Change getRelatedExistingExpansion() to return bool (NFC)
This method is only used to determine whether a related expansion exists, the actual value is unused. Clarify that by renaming get -> has and returning bool.
1 parent 341443d commit 7ed4b7e

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,20 +374,15 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
374374

375375
void setChainedPhi(PHINode *PN) { ChainedPhis.insert(PN); }
376376

377-
/// Try to find the ValueOffsetPair for S. The function is mainly used to
378-
/// check whether S can be expanded cheaply. If this returns a non-None
379-
/// value, we know we can codegen the `ValueOffsetPair` into a suitable
380-
/// expansion identical with S so that S can be expanded cheaply.
377+
/// Determine whether there is an existing expansion of S that can be reused.
378+
/// This is used to check whether S can be expanded cheaply.
381379
///
382380
/// L is a hint which tells in which loop to look for the suitable value.
383-
/// On success return value which is equivalent to the expanded S at point
384-
/// At. Return nullptr if value was not found.
385381
///
386382
/// Note that this function does not perform an exhaustive search. I.e if it
387383
/// didn't find any value it does not mean that there is no such value.
388-
///
389-
Value *getRelatedExistingExpansion(const SCEV *S, const Instruction *At,
390-
Loop *L);
384+
bool hasRelatedExistingExpansion(const SCEV *S, const Instruction *At,
385+
Loop *L);
391386

392387
/// Returns a suitable insert point after \p I, that dominates \p
393388
/// MustDominate. Skips instructions inserted by the expander.

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,9 +1744,9 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
17441744
return NumElim;
17451745
}
17461746

1747-
Value *SCEVExpander::getRelatedExistingExpansion(const SCEV *S,
1748-
const Instruction *At,
1749-
Loop *L) {
1747+
bool SCEVExpander::hasRelatedExistingExpansion(const SCEV *S,
1748+
const Instruction *At,
1749+
Loop *L) {
17501750
using namespace llvm::PatternMatch;
17511751

17521752
SmallVector<BasicBlock *, 4> ExitingBlocks;
@@ -1763,17 +1763,17 @@ Value *SCEVExpander::getRelatedExistingExpansion(const SCEV *S,
17631763
continue;
17641764

17651765
if (SE.getSCEV(LHS) == S && SE.DT.dominates(LHS, At))
1766-
return LHS;
1766+
return true;
17671767

17681768
if (SE.getSCEV(RHS) == S && SE.DT.dominates(RHS, At))
1769-
return RHS;
1769+
return true;
17701770
}
17711771

17721772
// Use expand's logic which is used for reusing a previous Value in
17731773
// ExprValueMap. Note that we don't currently model the cost of
17741774
// needing to drop poison generating flags on the instruction if we
17751775
// want to reuse it. We effectively assume that has zero cost.
1776-
return FindValueInExprValueMap(S, At);
1776+
return FindValueInExprValueMap(S, At) != nullptr;
17771777
}
17781778

17791779
template<typename T> static InstructionCost costAndCollectOperands(
@@ -1951,7 +1951,7 @@ bool SCEVExpander::isHighCostExpansionHelper(
19511951

19521952
// If we can find an existing value for this scev available at the point "At"
19531953
// then consider the expression cheap.
1954-
if (getRelatedExistingExpansion(S, &At, L))
1954+
if (hasRelatedExistingExpansion(S, &At, L))
19551955
return false; // Consider the expression to be free.
19561956

19571957
TargetTransformInfo::TargetCostKind CostKind =
@@ -1993,7 +1993,7 @@ bool SCEVExpander::isHighCostExpansionHelper(
19931993
// At the beginning of this function we already tried to find existing
19941994
// value for plain 'S'. Now try to lookup 'S + 1' since it is common
19951995
// pattern involving division. This is just a simple search heuristic.
1996-
if (getRelatedExistingExpansion(
1996+
if (hasRelatedExistingExpansion(
19971997
SE.getAddExpr(S, SE.getConstant(S->getType(), 1)), &At, L))
19981998
return false; // Consider it to be free.
19991999

0 commit comments

Comments
 (0)