[llvm] df77ce7 - [SCEV] Extract code to collect conditions to lambda (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 07:14:03 PDT 2020
Author: Florian Hahn
Date: 2020-09-25T15:12:42+01:00
New Revision: df77ce7cad081bf55042cf098b61b118dcdfc7e9
URL: https://github.com/llvm/llvm-project/commit/df77ce7cad081bf55042cf098b61b118dcdfc7e9
DIFF: https://github.com/llvm/llvm-project/commit/df77ce7cad081bf55042cf098b61b118dcdfc7e9.diff
LOG: [SCEV] Extract code to collect conditions to lambda (NFC).
This makes re-using the common functionality easier in follow-up
patches.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index c4e639e54e42..980c75f3073b 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12591,6 +12591,32 @@ const SCEV* ScalarEvolution::computeMaxBackedgeTakenCount(const Loop *L) {
}
const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
+ auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
+ const SCEV *RHS, ValueToSCEVMapTy &RewriteMap) {
+ // For now, limit to conditions that provide information about unknown
+ // expressions.
+ auto *LHSUnknown = dyn_cast<SCEVUnknown>(LHS);
+ if (!LHSUnknown)
+ return;
+
+ // TODO: use information from more predicates.
+ switch (Predicate) {
+ case CmpInst::ICMP_ULT: {
+ if (!containsAddRecurrence(RHS)) {
+ const SCEV *Base = LHS;
+ auto I = RewriteMap.find(LHSUnknown->getValue());
+ if (I != RewriteMap.end())
+ Base = I->second;
+
+ RewriteMap[LHSUnknown->getValue()] =
+ getUMinExpr(Base, getMinusSCEV(RHS, getOne(RHS->getType())));
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ };
// Starting at the loop predecessor, climb up the predecessor chain, as long
// as there are predecessors that can be found that have unique successors
// leading to the original header.
@@ -12613,26 +12639,8 @@ const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
auto Predicate = Cmp->getPredicate();
if (LoopEntryPredicate->getSuccessor(1) == Pair.second)
Predicate = CmpInst::getInversePredicate(Predicate);
- // TODO: use information from more predicates.
- switch (Predicate) {
- case CmpInst::ICMP_ULT: {
- const SCEV *LHS = getSCEV(Cmp->getOperand(0));
- const SCEV *RHS = getSCEV(Cmp->getOperand(1));
- if (isa<SCEVUnknown>(LHS) && !isa<UndefValue>(Cmp->getOperand(0)) &&
- !containsAddRecurrence(RHS)) {
- const SCEV *Base = LHS;
- auto I = RewriteMap.find(Cmp->getOperand(0));
- if (I != RewriteMap.end())
- Base = I->second;
-
- RewriteMap[Cmp->getOperand(0)] =
- getUMinExpr(Base, getMinusSCEV(RHS, getOne(RHS->getType())));
- }
- break;
- }
- default:
- break;
- }
+ CollectCondition(Predicate, getSCEV(Cmp->getOperand(0)),
+ getSCEV(Cmp->getOperand(1)), RewriteMap);
}
if (RewriteMap.empty())
More information about the llvm-commits
mailing list