[llvm] 9e6e631 - [LoopPredication] Use isSafeToExpandAt() member function (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 14 05:50:26 PDT 2022
Author: Nikita Popov
Date: 2022-07-14T14:49:07+02:00
New Revision: 9e6e631b3861c3f720992f037a9ba362b0c49974
URL: https://github.com/llvm/llvm-project/commit/9e6e631b3861c3f720992f037a9ba362b0c49974
DIFF: https://github.com/llvm/llvm-project/commit/9e6e631b3861c3f720992f037a9ba362b0c49974.diff
LOG: [LoopPredication] Use isSafeToExpandAt() member function (NFC)
As a followup to D129630, this switches a usage of the freestanding
function in LoopPredication to use the member variant instead. This
was the last use of the freestanding function, so drop it entirely.
Added:
Modified:
llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
llvm/lib/Transforms/Scalar/LoopPredication.cpp
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 a990bfc572626..10b95aa38150d 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -34,13 +34,6 @@ extern cl::opt<unsigned> SCEVCheapExpansionBudget;
/// CanonicalMode indicates whether the expander will be used in canonical mode.
bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE, bool CanonicalMode);
-/// Return true if the given expression is safe to expand in the sense that
-/// all materialized values are defined and safe to speculate at the specified
-/// location and their operands are defined at this location.
-/// CanonicalMode indicates whether the expander will be used in canonical mode.
-bool isSafeToExpandAt(const SCEV *S, const Instruction *InsertionPoint,
- ScalarEvolution &SE, bool CanonicalMode);
-
/// struct for holding enough information to help calculate the cost of the
/// given SCEV when expanded into IR.
struct SCEVOperand {
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
index d551a8331f677..b327d38d2a84c 100644
--- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
@@ -275,7 +275,8 @@ class LoopPredication {
/// which is that an expression *can be made* invariant via SCEVExpander.
/// Thus, this version is only suitable for finding an insert point to be be
/// passed to SCEVExpander!
- Instruction *findInsertPt(Instruction *User, ArrayRef<const SCEV*> Ops);
+ Instruction *findInsertPt(const SCEVExpander &Expander, Instruction *User,
+ ArrayRef<const SCEV *> Ops);
/// Return true if the value is known to produce a single fixed value across
/// all iterations on which it executes. Note that this does not imply
@@ -418,13 +419,14 @@ Value *LoopPredication::expandCheck(SCEVExpander &Expander,
return Builder.getFalse();
}
- Value *LHSV = Expander.expandCodeFor(LHS, Ty, findInsertPt(Guard, {LHS}));
- Value *RHSV = Expander.expandCodeFor(RHS, Ty, findInsertPt(Guard, {RHS}));
+ Value *LHSV =
+ Expander.expandCodeFor(LHS, Ty, findInsertPt(Expander, Guard, {LHS}));
+ Value *RHSV =
+ Expander.expandCodeFor(RHS, Ty, findInsertPt(Expander, Guard, {RHS}));
IRBuilder<> Builder(findInsertPt(Guard, {LHSV, RHSV}));
return Builder.CreateICmp(Pred, LHSV, RHSV);
}
-
// Returns true if its safe to truncate the IV to RangeCheckType.
// When the IV type is wider than the range operand type, we can still do loop
// predication, by generating SCEVs for the range and latch that are of the
@@ -516,15 +518,15 @@ Instruction *LoopPredication::findInsertPt(Instruction *Use,
return Preheader->getTerminator();
}
-Instruction *LoopPredication::findInsertPt(Instruction *Use,
- ArrayRef<const SCEV*> Ops) {
+Instruction *LoopPredication::findInsertPt(const SCEVExpander &Expander,
+ Instruction *Use,
+ ArrayRef<const SCEV *> Ops) {
// Subtlety: SCEV considers things to be invariant if the value produced is
// the same across iterations. This is not the same as being able to
// evaluate outside the loop, which is what we actually need here.
for (const SCEV *Op : Ops)
if (!SE->isLoopInvariant(Op, L) ||
- !isSafeToExpandAt(Op, Preheader->getTerminator(), *SE,
- /* CanonicalMode */ true))
+ !Expander.isSafeToExpandAt(Op, Preheader->getTerminator()))
return Use;
return Preheader->getTerminator();
}
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 8d3dbff18b0ff..67ce9824eb7e2 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -2561,11 +2561,6 @@ bool SCEVExpander::isSafeToExpand(const SCEV *S) const {
return llvm::isSafeToExpand(S, SE, CanonicalMode);
}
-bool SCEVExpander::isSafeToExpandAt(const SCEV *S,
- const Instruction *InsertionPoint) const {
- return llvm::isSafeToExpandAt(S, InsertionPoint, SE, CanonicalMode);
-}
-
namespace {
// Search for a SCEV subexpression that is not safe to expand. Any expression
// that may expand to a !isSafeToSpeculativelyExecute value is unsafe, namely
@@ -2622,7 +2617,7 @@ struct SCEVFindUnsafe {
}
bool isDone() const { return IsUnsafe; }
};
-}
+} // namespace
namespace llvm {
bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE, bool CanonicalMode) {
@@ -2631,9 +2626,9 @@ bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE, bool CanonicalMode) {
return !Search.IsUnsafe;
}
-bool isSafeToExpandAt(const SCEV *S, const Instruction *InsertionPoint,
- ScalarEvolution &SE, bool CanonicalMode) {
- if (!isSafeToExpand(S, SE, CanonicalMode))
+bool SCEVExpander::isSafeToExpandAt(const SCEV *S,
+ const Instruction *InsertionPoint) const {
+ if (!isSafeToExpand(S))
return false;
// We have to prove that the expanded site of S dominates InsertionPoint.
// This is easy when not in the same block, but hard when S is an instruction
More information about the llvm-commits
mailing list