Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 5e12a21

Browse files
author
Serguei Katkov
committed
Rename and move utility function getLatchPredicateForGuard. NFC.
Rename getLatchPredicateForGuard to more common name getFlippedStrictnessPredicate and move it to ICmpInst class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324717 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 099ec62 commit 5e12a21

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

include/llvm/IR/InstrTypes.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,21 @@ class CmpInst : public Instruction {
973973
/// @brief Return the predicate as if the operands were swapped.
974974
static Predicate getSwappedPredicate(Predicate pred);
975975

976+
/// For predicate of kind "is X or equal to 0" returns the predicate "is X".
977+
/// For predicate of kind "is X" returns the predicate "is X or equal to 0".
978+
/// does not support other kind of predicates.
979+
/// @returns the predicate that does not contains is equal to zero if
980+
/// it had and vice versa.
981+
/// @brief Return the flipped strictness of predicate
982+
Predicate getFlippedStrictnessPredicate() const {
983+
return getFlippedStrictnessPredicate(getPredicate());
984+
}
985+
986+
/// This is a static version that you can use without an instruction
987+
/// available.
988+
/// @brief Return the flipped strictness of predicate
989+
static Predicate getFlippedStrictnessPredicate(Predicate pred);
990+
976991
/// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
977992
/// @brief Returns the non-strict version of strict comparisons.
978993
Predicate getNonStrictPredicate() const {

lib/IR/Instructions.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,6 +3437,29 @@ ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) {
34373437
}
34383438
}
34393439

3440+
CmpInst::Predicate CmpInst::getFlippedStrictnessPredicate(Predicate pred) {
3441+
switch (pred) {
3442+
default: llvm_unreachable("Unknown or unsupported cmp predicate!");
3443+
case ICMP_SGT: return ICMP_SGE;
3444+
case ICMP_SLT: return ICMP_SLE;
3445+
case ICMP_SGE: return ICMP_SGT;
3446+
case ICMP_SLE: return ICMP_SLT;
3447+
case ICMP_UGT: return ICMP_UGE;
3448+
case ICMP_ULT: return ICMP_ULE;
3449+
case ICMP_UGE: return ICMP_UGT;
3450+
case ICMP_ULE: return ICMP_ULT;
3451+
3452+
case FCMP_OGT: return FCMP_OGE;
3453+
case FCMP_OLT: return FCMP_OLE;
3454+
case FCMP_OGE: return FCMP_OGT;
3455+
case FCMP_OLE: return FCMP_OLT;
3456+
case FCMP_UGT: return FCMP_UGE;
3457+
case FCMP_ULT: return FCMP_ULE;
3458+
case FCMP_UGE: return FCMP_UGT;
3459+
case FCMP_ULE: return FCMP_ULT;
3460+
}
3461+
}
3462+
34403463
CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
34413464
switch (pred) {
34423465
default: llvm_unreachable("Unknown cmp predicate!");

lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ class LoopPredication {
271271
// so.
272272
Optional<LoopICmp> generateLoopLatchCheck(Type *RangeCheckType);
273273

274-
// Returns the latch predicate for guard. SGT -> SGE, UGT -> UGE, SGE -> SGT,
275-
// UGE -> UGT, etc.
276-
ICmpInst::Predicate getLatchPredicateForGuard(ICmpInst::Predicate Pred);
277-
278274
public:
279275
LoopPredication(ScalarEvolution *SE) : SE(SE){};
280276
bool runOnLoop(Loop *L);
@@ -400,30 +396,6 @@ bool LoopPredication::CanExpand(const SCEV* S) {
400396
return SE->isLoopInvariant(S, L) && isSafeToExpand(S, *SE);
401397
}
402398

403-
ICmpInst::Predicate
404-
LoopPredication::getLatchPredicateForGuard(ICmpInst::Predicate Pred) {
405-
switch (LatchCheck.Pred) {
406-
case ICmpInst::ICMP_ULT:
407-
return ICmpInst::ICMP_ULE;
408-
case ICmpInst::ICMP_ULE:
409-
return ICmpInst::ICMP_ULT;
410-
case ICmpInst::ICMP_SLT:
411-
return ICmpInst::ICMP_SLE;
412-
case ICmpInst::ICMP_SLE:
413-
return ICmpInst::ICMP_SLT;
414-
case ICmpInst::ICMP_UGT:
415-
return ICmpInst::ICMP_UGE;
416-
case ICmpInst::ICMP_UGE:
417-
return ICmpInst::ICMP_UGT;
418-
case ICmpInst::ICMP_SGT:
419-
return ICmpInst::ICMP_SGE;
420-
case ICmpInst::ICMP_SGE:
421-
return ICmpInst::ICMP_SGT;
422-
default:
423-
llvm_unreachable("Unsupported loop latch!");
424-
}
425-
}
426-
427399
Optional<Value *> LoopPredication::widenICmpRangeCheckIncrementingLoop(
428400
LoopPredication::LoopICmp LatchCheck, LoopPredication::LoopICmp RangeCheck,
429401
SCEVExpander &Expander, IRBuilder<> &Builder) {
@@ -448,7 +420,8 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckIncrementingLoop(
448420
DEBUG(dbgs() << "Can't expand limit check!\n");
449421
return None;
450422
}
451-
auto LimitCheckPred = getLatchPredicateForGuard(LatchCheck.Pred);
423+
auto LimitCheckPred =
424+
ICmpInst::getFlippedStrictnessPredicate(LatchCheck.Pred);
452425

453426
DEBUG(dbgs() << "LHS: " << *LatchLimit << "\n");
454427
DEBUG(dbgs() << "RHS: " << *RHS << "\n");
@@ -489,7 +462,8 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckDecrementingLoop(
489462
// latchLimit <pred> 1.
490463
// See the header comment for reasoning of the checks.
491464
Instruction *InsertAt = Preheader->getTerminator();
492-
auto LimitCheckPred = getLatchPredicateForGuard(LatchCheck.Pred);
465+
auto LimitCheckPred =
466+
ICmpInst::getFlippedStrictnessPredicate(LatchCheck.Pred);
493467
auto *FirstIterationCheck = expandCheck(Expander, Builder, ICmpInst::ICMP_ULT,
494468
GuardStart, GuardLimit, InsertAt);
495469
auto *LimitCheck = expandCheck(Expander, Builder, LimitCheckPred, LatchLimit,

0 commit comments

Comments
 (0)