LLVM API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
llvm::CmpInst Class Reference

Abstract base class of comparison instructions. More...

#include <InstrTypes.h>

Inheritance diagram for llvm::CmpInst:
Inheritance graph
[legend]
Collaboration diagram for llvm::CmpInst:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Predicate {
  FCMP_FALSE = 0, FCMP_OEQ = 1, FCMP_OGT = 2, FCMP_OGE = 3,
  FCMP_OLT = 4, FCMP_OLE = 5, FCMP_ONE = 6, FCMP_ORD = 7,
  FCMP_UNO = 8, FCMP_UEQ = 9, FCMP_UGT = 10, FCMP_UGE = 11,
  FCMP_ULT = 12, FCMP_ULE = 13, FCMP_UNE = 14, FCMP_TRUE = 15,
  FIRST_FCMP_PREDICATE = FCMP_FALSE, LAST_FCMP_PREDICATE = FCMP_TRUE, BAD_FCMP_PREDICATE = FCMP_TRUE + 1, ICMP_EQ = 32,
  ICMP_NE = 33, ICMP_UGT = 34, ICMP_UGE = 35, ICMP_ULT = 36,
  ICMP_ULE = 37, ICMP_SGT = 38, ICMP_SGE = 39, ICMP_SLT = 40,
  ICMP_SLE = 41, FIRST_ICMP_PREDICATE = ICMP_EQ, LAST_ICMP_PREDICATE = ICMP_SLE, BAD_ICMP_PREDICATE = ICMP_SLE + 1
}

Public Member Functions

void * operator new (size_t s)
OtherOps getOpcode () const
 Get the opcode casted to the right type.
Predicate getPredicate () const
 Return the predicate for this instruction.
void setPredicate (Predicate P)
 Set the predicate for this instruction to the specified value.
bool isFPPredicate () const
bool isIntPredicate () const
Predicate getInversePredicate () const
 Return the inverse of the instruction's predicate.
Predicate getSwappedPredicate () const
 Return the predicate as if the operands were swapped.
 DECLARE_TRANSPARENT_OPERAND_ACCESSORS (Value)
 Provide more efficient getOperand methods.
void swapOperands ()
 Swap the operands and adjust predicate accordingly to retain the same comparison.
bool isCommutative () const
 Determine if this CmpInst is commutative.
bool isEquality () const
 Determine if this is an equals/not equals predicate.
bool isSigned () const
 Determine if this instruction is using a signed comparison.
bool isUnsigned () const
 Determine if this instruction is using an unsigned comparison.
bool isTrueWhenEqual () const
 Determine if this is true when both operands are the same.
bool isFalseWhenEqual () const
 Determine if this is false when both operands are the same.

Static Public Member Functions

static CmpInstCreate (OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Create a CmpInst.
static CmpInstCreate (OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name, BasicBlock *InsertAtEnd)
 Create a CmpInst.
static bool isFPPredicate (Predicate P)
static bool isIntPredicate (Predicate P)
static Predicate getInversePredicate (Predicate pred)
 Return the inverse of a given predicate.
static Predicate getSwappedPredicate (Predicate pred)
 Return the predicate as if the operands were swapped.
static bool isUnsigned (unsigned short predicate)
 Determine if the predicate is an unsigned operation.
static bool isSigned (unsigned short predicate)
 Determine if the predicate is an signed operation.
static bool isOrdered (unsigned short predicate)
 Determine if the predicate is an ordered operation.
static bool isUnordered (unsigned short predicate)
 Determine if the predicate is an unordered operation.
static bool isTrueWhenEqual (unsigned short predicate)
 Determine if the predicate is true when comparing a value with itself.
static bool isFalseWhenEqual (unsigned short predicate)
 Determine if the predicate is false when comparing a value with itself.
static bool classof (const Instruction *I)
 Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof (const Value *V)
 Methods for support type inquiry through isa, cast, and dyn_cast:
static TypemakeCmpResultType (Type *opnd_type)
 Create a result type for fcmp/icmp.

Protected Member Functions

 CmpInst (Type *ty, Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, const Twine &Name="", Instruction *InsertBefore=nullptr)
 CmpInst (Type *ty, Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd)
void anchor () override

Detailed Description

Abstract base class of comparison instructions.

This class is the base class for the comparison instructions.

Definition at line 653 of file InstrTypes.h.


Member Enumeration Documentation

This enumeration lists the possible predicates for CmpInst subclasses. Values in the range 0-31 are reserved for FCmpInst, while values in the range 32-64 are reserved for ICmpInst. This is necessary to ensure the predicate values are not overlapping between the classes.

Enumerator:
FCMP_FALSE 

0 0 0 0 Always false (always folded)

FCMP_OEQ 

0 0 0 1 True if ordered and equal

FCMP_OGT 

0 0 1 0 True if ordered and greater than

FCMP_OGE 

0 0 1 1 True if ordered and greater than or equal

FCMP_OLT 

0 1 0 0 True if ordered and less than

FCMP_OLE 

0 1 0 1 True if ordered and less than or equal

FCMP_ONE 

0 1 1 0 True if ordered and operands are unequal

FCMP_ORD 

0 1 1 1 True if ordered (no nans)

FCMP_UNO 

1 0 0 0 True if unordered: isnan(X) | isnan(Y)

FCMP_UEQ 

1 0 0 1 True if unordered or equal

FCMP_UGT 

1 0 1 0 True if unordered or greater than

FCMP_UGE 

1 0 1 1 True if unordered, greater than, or equal

FCMP_ULT 

1 1 0 0 True if unordered or less than

FCMP_ULE 

1 1 0 1 True if unordered, less than, or equal

FCMP_UNE 

1 1 1 0 True if unordered or not equal

FCMP_TRUE 

1 1 1 1 Always true (always folded)

FIRST_FCMP_PREDICATE 
LAST_FCMP_PREDICATE 
BAD_FCMP_PREDICATE 
ICMP_EQ 

equal

ICMP_NE 

not equal

ICMP_UGT 

unsigned greater than

ICMP_UGE 

unsigned greater or equal

ICMP_ULT 

unsigned less than

ICMP_ULE 

unsigned less or equal

ICMP_SGT 

signed greater than

ICMP_SGE 

signed greater or equal

ICMP_SLT 

signed less than

ICMP_SLE 

signed less or equal

FIRST_ICMP_PREDICATE 
LAST_ICMP_PREDICATE 
BAD_ICMP_PREDICATE 

Definition at line 671 of file InstrTypes.h.


Constructor & Destructor Documentation

CmpInst::CmpInst ( Type ty,
Instruction::OtherOps  op,
unsigned short  pred,
Value LHS,
Value RHS,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [protected]

Definition at line 3110 of file Instructions.cpp.

References llvm::Value::setName(), and setPredicate().

CmpInst::CmpInst ( Type ty,
Instruction::OtherOps  op,
unsigned short  pred,
Value LHS,
Value RHS,
const Twine Name,
BasicBlock InsertAtEnd 
) [protected]

Definition at line 3123 of file Instructions.cpp.

References llvm::Value::setName(), and setPredicate().


Member Function Documentation

void CmpInst::anchor ( ) [override, protected, virtual]

Reimplemented from llvm::User.

Definition at line 3108 of file Instructions.cpp.

static bool llvm::CmpInst::classof ( const Instruction I) [inline, static]

Methods for support type inquiry through isa, cast, and dyn_cast:

Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.

Definition at line 843 of file InstrTypes.h.

References llvm::FCmp, and llvm::Instruction::getOpcode().

Referenced by classof().

static bool llvm::CmpInst::classof ( const Value V) [inline, static]

Methods for support type inquiry through isa, cast, and dyn_cast:

Reimplemented from llvm::Instruction.

Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.

Definition at line 847 of file InstrTypes.h.

References classof().

CmpInst * CmpInst::Create ( OtherOps  Op,
unsigned short  predicate,
Value S1,
Value S2,
const Twine Name = "",
Instruction InsertBefore = nullptr 
) [static]

Create a CmpInst.

Construct a compare instruction, given the opcode, the predicate and the two operands. Optionally (if InstBefore is specified) insert the instruction into a BasicBlock right before the specified instruction. The specified Instruction is allowed to be a dereferenced end iterator.

Definition at line 3137 of file Instructions.cpp.

Referenced by llvm::ConstantExpr::getAsInstruction(), OptimizeCmpExpression(), llvm::InstCombiner::visitICmpInst(), and llvm::InstCombiner::visitXor().

CmpInst * CmpInst::Create ( OtherOps  Op,
unsigned short  predicate,
Value S1,
Value S2,
const Twine Name,
BasicBlock InsertAtEnd 
) [static]

Create a CmpInst.

Construct a compare instruction, given the opcode, the predicate and the two operands. Also automatically insert this instruction to the end of the BasicBlock specified.

Definition at line 3158 of file Instructions.cpp.

Provide more efficient getOperand methods.

Return the inverse of the instruction's predicate.

For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.

Returns:
the inverse predicate for the instruction's current predicate.

Definition at line 757 of file InstrTypes.h.

References getPredicate().

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::FoldBranchToCommonDest(), llvm::InstCombiner::FoldICmpCstShrCst(), llvm::getICmpCode(), SimplifyICmpInst(), llvm::InstCombiner::visitBranchInst(), and llvm::InstCombiner::visitICmpInst().

Return the inverse of a given predicate.

For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.

Returns:
the inverse predicate for predicate provided in pred.

Definition at line 3188 of file Instructions.cpp.

References FCMP_FALSE, FCMP_OEQ, FCMP_OGE, FCMP_OGT, FCMP_OLE, FCMP_OLT, FCMP_ONE, FCMP_ORD, FCMP_TRUE, FCMP_UEQ, FCMP_UGE, FCMP_UGT, FCMP_ULE, FCMP_ULT, FCMP_UNE, FCMP_UNO, ICMP_EQ, ICMP_NE, ICMP_SGE, ICMP_SGT, ICMP_SLE, ICMP_SLT, ICMP_UGE, ICMP_UGT, ICMP_ULE, ICMP_ULT, and llvm_unreachable.

OtherOps llvm::CmpInst::getOpcode ( ) const [inline]

Get the opcode casted to the right type.

Reimplemented from llvm::Instruction.

Definition at line 729 of file InstrTypes.h.

Referenced by OptimizeCmpExpression(), and llvm::InstCombiner::visitXor().

Return the predicate for this instruction.

Definition at line 734 of file InstrTypes.h.

References llvm::Instruction::getSubclassDataFromInstruction().

Referenced by canFoldZeroCheckIntoBranch(), llvm::ICmpInst::clone_impl(), llvm::FCmpInst::clone_impl(), decomposeBitTestICmp(), DemandedBitsLHSMask(), ExtractEquivalentCondition(), llvm::InstCombiner::FoldAndOfFCmps(), llvm::InstCombiner::FoldAndOfICmps(), llvm::InstCombiner::FoldCmpLoadFromIndexedGlobal(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::InstCombiner::FoldICmpCstShrCst(), llvm::InstCombiner::FoldICmpDivCst(), llvm::InstCombiner::FoldICmpShrCst(), foldLogOpOfMaskedICmps(), llvm::InstCombiner::FoldOrOfFCmps(), llvm::InstCombiner::FoldOrOfICmps(), foldSelectICmpAnd(), foldSelectICmpAndOr(), llvm::getICmpCode(), getInversePredicate(), getSwappedPredicate(), getValueFromFromCondition(), llvm::FCmpInst::isCommutative(), llvm::FCmpInst::isEquality(), isFalseWhenEqual(), isFPPredicate(), isIntPredicate(), isSameCompare(), isSigned(), isTrueWhenEqual(), isUnsigned(), MatchSelectPattern(), needsLFTR(), OptimizeCmpExpression(), llvm::FastISel::optimizeCmpPredicate(), OptimizeGlobalAddressOfMalloc(), ProcessUMulZExtIdiom(), TryToSimplifyUncondBranchWithICmpInIt(), llvm::Interpreter::visitFCmpInst(), llvm::InstCombiner::visitFCmpInst(), llvm::Interpreter::visitICmpInst(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithCastAndCast(), llvm::InstCombiner::visitICmpInstWithInstAndIntCst(), and llvm::InstCombiner::visitSelectInstWithICmp().

Return the predicate as if the operands were swapped.

For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.

Returns:
the predicate that would be the result of exchanging the two operands of the CmpInst instruction without changing the result produced.

Definition at line 773 of file InstrTypes.h.

References getPredicate().

Referenced by llvm::ConstantFoldCompareInstruction(), evaluateFCmpRelation(), evaluateICmpRelation(), ExtractEquivalentCondition(), llvm::FCmpInst::swapOperands(), llvm::InstCombiner::visitFCmpInst(), llvm::InstCombiner::visitICmpInst(), and llvm::InstCombiner::visitICmpInstWithInstAndIntCst().

Return the predicate as if the operands were swapped.

This is a static version that you can use without an instruction available.

Definition at line 3310 of file Instructions.cpp.

References FCMP_FALSE, FCMP_OEQ, FCMP_OGE, FCMP_OGT, FCMP_OLE, FCMP_OLT, FCMP_ONE, FCMP_ORD, FCMP_TRUE, FCMP_UEQ, FCMP_UGE, FCMP_UGT, FCMP_ULE, FCMP_ULT, FCMP_UNE, FCMP_UNO, ICMP_EQ, ICMP_NE, ICMP_SGE, ICMP_SGT, ICMP_SLE, ICMP_SLT, ICMP_UGE, ICMP_UGT, ICMP_ULE, ICMP_ULT, and llvm_unreachable.

Determine if this CmpInst is commutative.

This is just a convenience that dispatches to the subclasses.

Reimplemented from llvm::Instruction.

Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.

Definition at line 3175 of file Instructions.cpp.

Determine if this is an equals/not equals predicate.

This is just a convenience that dispatches to the subclasses.

Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.

Definition at line 3181 of file Instructions.cpp.

Determine if this is false when both operands are the same.

This is just a convenience.

Definition at line 818 of file InstrTypes.h.

References getPredicate().

Referenced by SimplifyFCmpInst(), and llvm::ScalarEvolution::SimplifyICmpOperands().

bool CmpInst::isFalseWhenEqual ( unsigned short  predicate) [static]

Determine if the predicate is false when comparing a value with itself.

Definition at line 3382 of file Instructions.cpp.

References FCMP_FALSE, FCMP_OGT, FCMP_OLT, FCMP_ONE, ICMP_NE, ICMP_SGT, ICMP_SLT, ICMP_UGT, and ICMP_ULT.

static bool llvm::CmpInst::isFPPredicate ( Predicate  P) [inline, static]

Definition at line 741 of file InstrTypes.h.

References FIRST_FCMP_PREDICATE, and LAST_FCMP_PREDICATE.

bool llvm::CmpInst::isFPPredicate ( ) const [inline]

Definition at line 749 of file InstrTypes.h.

References getPredicate(), and isFPPredicate().

Referenced by isFPPredicate(), and SimplifyFCmpInst().

static bool llvm::CmpInst::isIntPredicate ( Predicate  P) [inline, static]

Definition at line 745 of file InstrTypes.h.

References FIRST_ICMP_PREDICATE, and LAST_ICMP_PREDICATE.

bool llvm::CmpInst::isIntPredicate ( ) const [inline]

Definition at line 750 of file InstrTypes.h.

References getPredicate(), and isIntPredicate().

Referenced by isIntPredicate(), SimplifyCmpInst(), and SimplifyICmpInst().

bool CmpInst::isOrdered ( unsigned short  predicate) [static]

Determine if the predicate is an ordered operation.

Definition at line 3356 of file Instructions.cpp.

References FCMP_OEQ, FCMP_OGE, FCMP_OGT, FCMP_OLE, FCMP_OLT, FCMP_ONE, and FCMP_ORD.

Referenced by SimplifyFCmpInst().

bool llvm::CmpInst::isSigned ( ) const [inline]
bool CmpInst::isSigned ( unsigned short  predicate) [static]

Determine if the predicate is an signed operation.

Returns:
true if the predicate is signed, false otherwise.

Definition at line 3348 of file Instructions.cpp.

References ICMP_SGE, ICMP_SGT, ICMP_SLE, and ICMP_SLT.

Determine if this is true when both operands are the same.

This is just a convenience.

Definition at line 812 of file InstrTypes.h.

References getPredicate().

Referenced by computePointerICmp(), llvm::ConstantFoldCompareInstruction(), llvm::InstCombiner::FoldGEPICmp(), SimplifyFCmpInst(), SimplifyICmpInst(), and llvm::ScalarEvolution::SimplifyICmpOperands().

bool CmpInst::isTrueWhenEqual ( unsigned short  predicate) [static]

Determine if the predicate is true when comparing a value with itself.

Definition at line 3374 of file Instructions.cpp.

References FCMP_TRUE, FCMP_UEQ, FCMP_UGE, FCMP_ULE, ICMP_EQ, ICMP_SGE, ICMP_SLE, ICMP_UGE, and ICMP_ULE.

bool CmpInst::isUnordered ( unsigned short  predicate) [static]

Determine if the predicate is an unordered operation.

Definition at line 3365 of file Instructions.cpp.

References FCMP_UEQ, FCMP_UGE, FCMP_UGT, FCMP_ULE, FCMP_ULT, FCMP_UNE, and FCMP_UNO.

Referenced by SimplifyFCmpInst().

bool llvm::CmpInst::isUnsigned ( ) const [inline]

Determine if this instruction is using an unsigned comparison.

Returns:
true if the comparison is unsigned, false otherwise.

Definition at line 806 of file InstrTypes.h.

References getPredicate().

Referenced by SimplifyICmpInst(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithInstAndIntCst(), and llvm::InstCombiner::visitSelectInstWithICmp().

bool CmpInst::isUnsigned ( unsigned short  predicate) [static]

Determine if the predicate is an unsigned operation.

Returns:
true if the predicate is unsigned, false otherwise.

Definition at line 3340 of file Instructions.cpp.

References ICMP_UGE, ICMP_UGT, ICMP_ULE, and ICMP_ULT.

static Type* llvm::CmpInst::makeCmpResultType ( Type opnd_type) [inline, static]
void* llvm::CmpInst::operator new ( size_t  s) [inline]

Reimplemented from llvm::User.

Definition at line 708 of file InstrTypes.h.

void llvm::CmpInst::setPredicate ( Predicate  P) [inline]

Swap the operands and adjust predicate accordingly to retain the same comparison.

This is just a convenience that dispatches to the subclasses.

Reimplemented in llvm::FCmpInst, and llvm::ICmpInst.

Definition at line 3168 of file Instructions.cpp.


The documentation for this class was generated from the following files: