From c7c702a272f6b1a3578460eefc07e1282b43cf13 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 6 Nov 2020 10:36:30 +0300 Subject: [PATCH] [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.. --- llvm/include/llvm/IR/InstrTypes.h | 8 ++++++-- llvm/lib/IR/Instructions.cpp | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index e1c35bf..563b9d9 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -891,9 +891,13 @@ public: /// 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 950a1e9..43588aa 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -3682,10 +3682,12 @@ bool CmpInst::isCommutative() const { return cast(this)->isCommutative(); } -bool CmpInst::isEquality() const { - if (const ICmpInst *IC = dyn_cast(this)) - return IC->isEquality(); - return cast(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) { -- 2.7.4