/// @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 {
}
}
+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!");
// 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);
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) {
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");
// 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,