1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

Rename and move utility function getLatchPredicateForGuard. NFC.

Rename getLatchPredicateForGuard to more common name
getFlippedStrictnessPredicate and move it to ICmpInst class.

llvm-svn: 324717
This commit is contained in:
Serguei Katkov 2018-02-09 07:59:07 +00:00
parent f3f1685646
commit 600ac22cb2
3 changed files with 42 additions and 30 deletions

View File

@ -973,6 +973,21 @@ public:
/// @brief Return the predicate as if the operands were swapped.
static Predicate getSwappedPredicate(Predicate pred);
/// For predicate of kind "is X or equal to 0" returns the predicate "is X".
/// For predicate of kind "is X" returns the predicate "is X or equal to 0".
/// does not support other kind of predicates.
/// @returns the predicate that does not contains is equal to zero if
/// it had and vice versa.
/// @brief Return the flipped strictness of predicate
Predicate getFlippedStrictnessPredicate() const {
return getFlippedStrictnessPredicate(getPredicate());
}
/// This is a static version that you can use without an instruction
/// available.
/// @brief Return the flipped strictness of predicate
static Predicate getFlippedStrictnessPredicate(Predicate pred);
/// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
/// @brief Returns the non-strict version of strict comparisons.
Predicate getNonStrictPredicate() const {

View File

@ -3437,6 +3437,29 @@ ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) {
}
}
CmpInst::Predicate CmpInst::getFlippedStrictnessPredicate(Predicate pred) {
switch (pred) {
default: llvm_unreachable("Unknown or unsupported cmp predicate!");
case ICMP_SGT: return ICMP_SGE;
case ICMP_SLT: return ICMP_SLE;
case ICMP_SGE: return ICMP_SGT;
case ICMP_SLE: return ICMP_SLT;
case ICMP_UGT: return ICMP_UGE;
case ICMP_ULT: return ICMP_ULE;
case ICMP_UGE: return ICMP_UGT;
case ICMP_ULE: return ICMP_ULT;
case FCMP_OGT: return FCMP_OGE;
case FCMP_OLT: return FCMP_OLE;
case FCMP_OGE: return FCMP_OGT;
case FCMP_OLE: return FCMP_OLT;
case FCMP_UGT: return FCMP_UGE;
case FCMP_ULT: return FCMP_ULE;
case FCMP_UGE: return FCMP_UGT;
case FCMP_ULE: return FCMP_ULT;
}
}
CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
default: llvm_unreachable("Unknown cmp predicate!");

View File

@ -271,10 +271,6 @@ class LoopPredication {
// so.
Optional<LoopICmp> generateLoopLatchCheck(Type *RangeCheckType);
// Returns the latch predicate for guard. SGT -> SGE, UGT -> UGE, SGE -> SGT,
// UGE -> UGT, etc.
ICmpInst::Predicate getLatchPredicateForGuard(ICmpInst::Predicate Pred);
public:
LoopPredication(ScalarEvolution *SE) : SE(SE){};
bool runOnLoop(Loop *L);
@ -400,30 +396,6 @@ bool LoopPredication::CanExpand(const SCEV* S) {
return SE->isLoopInvariant(S, L) && isSafeToExpand(S, *SE);
}
ICmpInst::Predicate
LoopPredication::getLatchPredicateForGuard(ICmpInst::Predicate Pred) {
switch (LatchCheck.Pred) {
case ICmpInst::ICMP_ULT:
return ICmpInst::ICMP_ULE;
case ICmpInst::ICMP_ULE:
return ICmpInst::ICMP_ULT;
case ICmpInst::ICMP_SLT:
return ICmpInst::ICMP_SLE;
case ICmpInst::ICMP_SLE:
return ICmpInst::ICMP_SLT;
case ICmpInst::ICMP_UGT:
return ICmpInst::ICMP_UGE;
case ICmpInst::ICMP_UGE:
return ICmpInst::ICMP_UGT;
case ICmpInst::ICMP_SGT:
return ICmpInst::ICMP_SGE;
case ICmpInst::ICMP_SGE:
return ICmpInst::ICMP_SGT;
default:
llvm_unreachable("Unsupported loop latch!");
}
}
Optional<Value *> LoopPredication::widenICmpRangeCheckIncrementingLoop(
LoopPredication::LoopICmp LatchCheck, LoopPredication::LoopICmp RangeCheck,
SCEVExpander &Expander, IRBuilder<> &Builder) {
@ -448,7 +420,8 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckIncrementingLoop(
DEBUG(dbgs() << "Can't expand limit check!\n");
return None;
}
auto LimitCheckPred = getLatchPredicateForGuard(LatchCheck.Pred);
auto LimitCheckPred =
ICmpInst::getFlippedStrictnessPredicate(LatchCheck.Pred);
DEBUG(dbgs() << "LHS: " << *LatchLimit << "\n");
DEBUG(dbgs() << "RHS: " << *RHS << "\n");
@ -489,7 +462,8 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckDecrementingLoop(
// latchLimit <pred> 1.
// See the header comment for reasoning of the checks.
Instruction *InsertAt = Preheader->getTerminator();
auto LimitCheckPred = getLatchPredicateForGuard(LatchCheck.Pred);
auto LimitCheckPred =
ICmpInst::getFlippedStrictnessPredicate(LatchCheck.Pred);
auto *FirstIterationCheck = expandCheck(Expander, Builder, ICmpInst::ICMP_ULT,
GuardStart, GuardLimit, InsertAt);
auto *LimitCheck = expandCheck(Expander, Builder, LimitCheckPred, LatchLimit,