[llvm] 7ed4b7e - [SCEVExpander] Change getRelatedExistingExpansion() to return bool (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 21 02:51:32 PDT 2023
Author: Nikita Popov
Date: 2023-08-21T11:51:22+02:00
New Revision: 7ed4b7e5837d71c63b0892fef89b97fe0ce205cf
URL: https://github.com/llvm/llvm-project/commit/7ed4b7e5837d71c63b0892fef89b97fe0ce205cf
DIFF: https://github.com/llvm/llvm-project/commit/7ed4b7e5837d71c63b0892fef89b97fe0ce205cf.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index 02b9e51f354a13..4b314d7944e9e4 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -374,20 +374,15 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
void setChainedPhi(PHINode *PN) { ChainedPhis.insert(PN); }
- /// Try to find the ValueOffsetPair for S. The function is mainly used to
- /// check whether S can be expanded cheaply. If this returns a non-None
- /// value, we know we can codegen the `ValueOffsetPair` into a suitable
- /// expansion identical with S so that S can be expanded cheaply.
+ /// Determine whether there is an existing expansion of S that can be reused.
+ /// This is used to check whether S can be expanded cheaply.
///
/// L is a hint which tells in which loop to look for the suitable value.
- /// On success return value which is equivalent to the expanded S at point
- /// At. Return nullptr if value was not found.
///
/// Note that this function does not perform an exhaustive search. I.e if it
/// didn't find any value it does not mean that there is no such value.
- ///
- Value *getRelatedExistingExpansion(const SCEV *S, const Instruction *At,
- Loop *L);
+ bool hasRelatedExistingExpansion(const SCEV *S, const Instruction *At,
+ Loop *L);
/// Returns a suitable insert point after \p I, that dominates \p
/// MustDominate. Skips instructions inserted by the expander.
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index a6c7e0628a0c19..ef65d3f4d882ac 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1744,9 +1744,9 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
return NumElim;
}
-Value *SCEVExpander::getRelatedExistingExpansion(const SCEV *S,
- const Instruction *At,
- Loop *L) {
+bool SCEVExpander::hasRelatedExistingExpansion(const SCEV *S,
+ const Instruction *At,
+ Loop *L) {
using namespace llvm::PatternMatch;
SmallVector<BasicBlock *, 4> ExitingBlocks;
@@ -1763,17 +1763,17 @@ Value *SCEVExpander::getRelatedExistingExpansion(const SCEV *S,
continue;
if (SE.getSCEV(LHS) == S && SE.DT.dominates(LHS, At))
- return LHS;
+ return true;
if (SE.getSCEV(RHS) == S && SE.DT.dominates(RHS, At))
- return RHS;
+ return true;
}
// Use expand's logic which is used for reusing a previous Value in
// ExprValueMap. Note that we don't currently model the cost of
// needing to drop poison generating flags on the instruction if we
// want to reuse it. We effectively assume that has zero cost.
- return FindValueInExprValueMap(S, At);
+ return FindValueInExprValueMap(S, At) != nullptr;
}
template<typename T> static InstructionCost costAndCollectOperands(
@@ -1951,7 +1951,7 @@ bool SCEVExpander::isHighCostExpansionHelper(
// If we can find an existing value for this scev available at the point "At"
// then consider the expression cheap.
- if (getRelatedExistingExpansion(S, &At, L))
+ if (hasRelatedExistingExpansion(S, &At, L))
return false; // Consider the expression to be free.
TargetTransformInfo::TargetCostKind CostKind =
@@ -1993,7 +1993,7 @@ bool SCEVExpander::isHighCostExpansionHelper(
// At the beginning of this function we already tried to find existing
// value for plain 'S'. Now try to lookup 'S + 1' since it is common
// pattern involving division. This is just a simple search heuristic.
- if (getRelatedExistingExpansion(
+ if (hasRelatedExistingExpansion(
SE.getAddExpr(S, SE.getConstant(S->getType(), 1)), &At, L))
return false; // Consider it to be free.
More information about the llvm-commits
mailing list