[llvm] c7c702a - [IR] CmpInst: add isEquality(Pred)
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 6 00:31:46 PST 2020
Author: Roman Lebedev
Date: 2020-11-06T11:31:09+03:00
New Revision: c7c702a272f6b1a3578460eefc07e1282b43cf13
URL: https://github.com/llvm/llvm-project/commit/c7c702a272f6b1a3578460eefc07e1282b43cf13
DIFF: https://github.com/llvm/llvm-project/commit/c7c702a272f6b1a3578460eefc07e1282b43cf13.diff
LOG: [IR] CmpInst: add isEquality(Pred)
Currently there is only a member version of isEquality(),
which requires an actual [IF]CmpInst to be avaliable,
which isn't always possible, and is inconsistent with
the general pattern here.
I wanted to use it in a new patch, but it wasn't there..
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 e1c35bfdb13d..563b9d99b4f2 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -891,9 +891,13 @@ class CmpInst : public Instruction {
/// Determine if this CmpInst is commutative.
bool isCommutative() const;
- /// This is just a convenience that dispatches to the subclasses.
/// Determine if this is an equals/not equals predicate.
- bool isEquality() const;
+ /// This is a static version that you can use without an instruction
+ /// available.
+ static bool isEquality(Predicate pred);
+
+ /// Determine if this is an equals/not equals predicate.
+ bool isEquality() const { return isEquality(getPredicate()); }
/// @returns true if the comparison is signed, false otherwise.
/// Determine if this instruction is using a signed comparison.
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 950a1e9fb508..43588aa7f6d5 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -3682,10 +3682,12 @@ bool CmpInst::isCommutative() const {
return cast<FCmpInst>(this)->isCommutative();
}
-bool CmpInst::isEquality() const {
- if (const ICmpInst *IC = dyn_cast<ICmpInst>(this))
- return IC->isEquality();
- return cast<FCmpInst>(this)->isEquality();
+bool CmpInst::isEquality(Predicate P) {
+ if (ICmpInst::isIntPredicate(P))
+ return ICmpInst::isEquality(P);
+ if (FCmpInst::isFPPredicate(P))
+ return FCmpInst::isEquality(P);
+ llvm_unreachable("Unsupported predicate kind");
}
CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
More information about the llvm-commits
mailing list