[llvm] r324717 - Rename and move utility function getLatchPredicateForGuard. NFC.
Serguei Katkov via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 23:59:08 PST 2018
Author: skatkov
Date: Thu Feb 8 23:59:07 2018
New Revision: 324717
URL: http://llvm.org/viewvc/llvm-project?rev=324717&view=rev
Log:
Rename and move utility function getLatchPredicateForGuard. NFC.
Rename getLatchPredicateForGuard to more common name
getFlippedStrictnessPredicate and move it to ICmpInst class.
Modified:
llvm/trunk/include/llvm/IR/InstrTypes.h
llvm/trunk/lib/IR/Instructions.cpp
llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp
Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=324717&r1=324716&r2=324717&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Thu Feb 8 23:59:07 2018
@@ -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 {
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=324717&r1=324716&r2=324717&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Thu Feb 8 23:59:07 2018
@@ -3437,6 +3437,29 @@ ICmpInst::Predicate ICmpInst::getUnsigne
}
}
+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!");
Modified: llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp?rev=324717&r1=324716&r2=324717&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp Thu Feb 8 23:59:07 2018
@@ -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 SC
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::widen
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::widen
// 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,
More information about the llvm-commits
mailing list