[llvm-branch-commits] [llvm] a2876ec - [NFC][Instructions] Refactor CmpInst::getFlippedStrictnessPredicate() in terms of is{, Non}StrictPredicate()/get{Non, }StrictPredicate()
Roman Lebedev via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 9 01:48:42 PST 2020
Author: Roman Lebedev
Date: 2020-12-09T12:43:08+03:00
New Revision: a2876ec74f8219e00d8e0e86e6296caa642eb811
URL: https://github.com/llvm/llvm-project/commit/a2876ec74f8219e00d8e0e86e6296caa642eb811
DIFF: https://github.com/llvm/llvm-project/commit/a2876ec74f8219e00d8e0e86e6296caa642eb811.diff
LOG: [NFC][Instructions] Refactor CmpInst::getFlippedStrictnessPredicate() in terms of is{,Non}StrictPredicate()/get{Non,}StrictPredicate()
In particular, this creates getStrictPredicate() method,
to be symmetrical with already-existing getNonStrictPredicate().
Added:
Modified:
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/IR/Instructions.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 23e030e94953..8af18e14c474 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -845,20 +845,38 @@ class CmpInst : public Instruction {
/// 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.
- /// 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.
+ /// @returns true if the comparison predicate is strict, false otherwise.
+ static bool isStrictPredicate(Predicate predicate);
+
+ /// @returns true if the comparison predicate is strict, false otherwise.
+ /// Determine if this instruction is using an strict comparison predicate.
+ bool isStrictPredicate() const { return isStrictPredicate(getPredicate()); }
+
+ /// This is a static version that you can use without an instruction
+ /// available.
+ /// @returns true if the comparison predicate is non-strict, false otherwise.
+ static bool isNonStrictPredicate(Predicate predicate);
+
+ /// @returns true if the comparison predicate is non-strict, false otherwise.
+ /// Determine if this instruction is using an non-strict comparison predicate.
+ bool isNonStrictPredicate() const {
+ return isNonStrictPredicate(getPredicate());
+ }
+
+ /// For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
+ /// Returns the strict version of non-strict comparisons.
+ Predicate getStrictPredicate() const {
+ return getStrictPredicate(getPredicate());
}
/// This is a static version that you can use without an instruction
/// available.
- /// Return the flipped strictness of predicate
- static Predicate getFlippedStrictnessPredicate(Predicate pred);
+ /// @returns the strict version of comparison provided in \p pred.
+ /// If \p pred is not a strict comparison predicate, returns \p pred.
+ /// Returns the strict version of non-strict comparisons.
+ static Predicate getStrictPredicate(Predicate pred);
/// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
/// Returns the non-strict version of strict comparisons.
@@ -873,6 +891,21 @@ class CmpInst : public Instruction {
/// Returns the non-strict version of strict comparisons.
static Predicate getNonStrictPredicate(Predicate pred);
+ /// This is a static version that you can use without an instruction
+ /// available.
+ /// Return the flipped strictness of predicate
+ static Predicate getFlippedStrictnessPredicate(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.
+ /// Return the flipped strictness of predicate
+ Predicate getFlippedStrictnessPredicate() const {
+ return getFlippedStrictnessPredicate(getPredicate());
+ }
+
/// Provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index cfc6d05ecaba..282746619d22 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -3735,29 +3735,6 @@ 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!");
@@ -3788,20 +3765,95 @@ CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
}
}
+bool CmpInst::isNonStrictPredicate(Predicate pred) {
+ switch (pred) {
+ case ICMP_SGE:
+ case ICMP_SLE:
+ case ICMP_UGE:
+ case ICMP_ULE:
+ case FCMP_OGE:
+ case FCMP_OLE:
+ case FCMP_UGE:
+ case FCMP_ULE:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool CmpInst::isStrictPredicate(Predicate pred) {
+ switch (pred) {
+ case ICMP_SGT:
+ case ICMP_SLT:
+ case ICMP_UGT:
+ case ICMP_ULT:
+ case FCMP_OGT:
+ case FCMP_OLT:
+ case FCMP_UGT:
+ case FCMP_ULT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+CmpInst::Predicate CmpInst::getStrictPredicate(Predicate pred) {
+ switch (pred) {
+ case ICMP_SGE:
+ return ICMP_SGT;
+ case ICMP_SLE:
+ return ICMP_SLT;
+ case ICMP_UGE:
+ return ICMP_UGT;
+ case ICMP_ULE:
+ return ICMP_ULT;
+ case FCMP_OGE:
+ return FCMP_OGT;
+ case FCMP_OLE:
+ return FCMP_OLT;
+ case FCMP_UGE:
+ return FCMP_UGT;
+ case FCMP_ULE:
+ return FCMP_ULT;
+ default:
+ return pred;
+ }
+}
+
CmpInst::Predicate CmpInst::getNonStrictPredicate(Predicate pred) {
switch (pred) {
- case ICMP_SGT: return ICMP_SGE;
- case ICMP_SLT: return ICMP_SLE;
- case ICMP_UGT: return ICMP_UGE;
- case ICMP_ULT: return ICMP_ULE;
- case FCMP_OGT: return FCMP_OGE;
- case FCMP_OLT: return FCMP_OLE;
- case FCMP_UGT: return FCMP_UGE;
- case FCMP_ULT: return FCMP_ULE;
- default: return pred;
+ case ICMP_SGT:
+ return ICMP_SGE;
+ case ICMP_SLT:
+ return ICMP_SLE;
+ case ICMP_UGT:
+ return ICMP_UGE;
+ case ICMP_ULT:
+ return ICMP_ULE;
+ case FCMP_OGT:
+ return FCMP_OGE;
+ case FCMP_OLT:
+ return FCMP_OLE;
+ case FCMP_UGT:
+ return FCMP_UGE;
+ case FCMP_ULT:
+ return FCMP_ULE;
+ default:
+ return pred;
}
}
+CmpInst::Predicate CmpInst::getFlippedStrictnessPredicate(Predicate pred) {
+ assert(CmpInst::isRelational(pred) && "Call only with relational predicate!");
+
+ if (isStrictPredicate(pred))
+ return getNonStrictPredicate(pred);
+ if (isNonStrictPredicate(pred))
+ return getStrictPredicate(pred);
+
+ llvm_unreachable("Unknown predicate!");
+}
+
CmpInst::Predicate CmpInst::getSignedPredicate(Predicate pred) {
assert(CmpInst::isUnsigned(pred) && "Call only with unsigned predicates!");
More information about the llvm-branch-commits
mailing list