1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[SCEV] Extract code to collect conditions to lambda (NFC).

This makes re-using the common functionality easier in follow-up
patches.
This commit is contained in:
Florian Hahn 2020-09-24 18:01:55 +01:00
parent d7750b1c5c
commit 18059fbd55

View File

@ -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())