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

This class is the base class for the 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
}
 This enumeration lists the possible predicates for CmpInst subclasses. More...

Public Member Functions

void * operator new (size_t s)
 Allocate a User with an operand pointer co-allocated.
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
 For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Predicate getSwappedPredicate () const
 For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
 DECLARE_TRANSPARENT_OPERAND_ACCESSORS (Value)
 Provide more efficient getOperand methods.
void swapOperands ()
 This is just a convenience that dispatches to the subclasses.
bool isCommutative () const
 This is just a convenience that dispatches to the subclasses.
bool isEquality () const
 This is just a convenience that dispatches to the subclasses.
bool isSigned () const
 Determine if this instruction is using a signed comparison.
bool isUnsigned () const
 Determine if this instruction is using an unsigned comparison.
Predicate getSignedPredicate ()
 For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert.
bool isTrueWhenEqual () const
 This is just a convenience.
bool isFalseWhenEqual () const
 This is just a convenience.

Static Public Member Functions

static CmpInstCreate (OtherOps Op, Predicate predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
 Construct a compare instruction, given the opcode, the predicate and the two operands.
static CmpInstCreate (OtherOps Op, Predicate predicate, Value *S1, Value *S2, const Twine &Name, BasicBlock *InsertAtEnd)
 Construct a compare instruction, given the opcode, the predicate and the two operands.
static bool isFPPredicate (Predicate P)
static bool isIntPredicate (Predicate P)
static Predicate getInversePredicate (Predicate pred)
 For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
static Predicate getSwappedPredicate (Predicate pred)
 This is a static version that you can use without an instruction available.
static Predicate getSignedPredicate (Predicate pred)
 For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert.
static bool isUnsigned (Predicate predicate)
 Determine if the predicate is an unsigned operation.
static bool isSigned (Predicate predicate)
 Determine if the predicate is an signed operation.
static bool isOrdered (Predicate predicate)
 Determine if the predicate is an ordered operation.
static bool isUnordered (Predicate predicate)
 Determine if the predicate is an unordered operation.
static bool isTrueWhenEqual (Predicate predicate)
 Determine if the predicate is true when comparing a value with itself.
static bool isFalseWhenEqual (Predicate 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, Predicate pred, Value *LHS, Value *RHS, const Twine &Name="", Instruction *InsertBefore=nullptr)
 CmpInst (Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd)
void anchor () override

Detailed Description

This class is the base class for the comparison instructions.

Abstract base class of comparison instructions.

Definition at line 876 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 882 of file InstrTypes.h.


Constructor & Destructor Documentation

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

Definition at line 3284 of file Instructions.cpp.

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

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

Definition at line 3296 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 3282 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 1082 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 1086 of file InstrTypes.h.

References classof().

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

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. Create a CmpInst

Definition at line 3309 of file Instructions.cpp.

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

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

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. Create a CmpInst

Definition at line 3329 of file Instructions.cpp.

Provide more efficient getOperand methods.

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. Return the inverse of the instruction's predicate.

Definition at line 983 of file InstrTypes.h.

References getPredicate().

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::FoldBranchToCommonDest(), llvm::InstCombiner::FoldICmpCstShlCst(), llvm::InstCombiner::FoldICmpCstShrCst(), llvm::getICmpCode(), llvm::ScalarEvolution::isLoopInvariantPredicate(), llvm::ConstantRange::makeSatisfyingICmpRegion(), SimplifyICmpInst(), llvm::InstCombiner::simplifyRangeCheck(), llvm::InstCombiner::visitBranchInst(), and llvm::InstCombiner::visitICmpInst().

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

Returns:
the inverse predicate for predicate provided in pred. Return the inverse of a given predicate

Definition at line 3359 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 956 of file InstrTypes.h.

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

Return the predicate for this instruction.

Definition at line 961 of file InstrTypes.h.

References llvm::Instruction::getSubclassDataFromInstruction().

Referenced by llvm::ICmpInst::cloneImpl(), llvm::FCmpInst::cloneImpl(), computeKnownBitsFromTrueCondition(), decomposeBitTestICmp(), DemandedBitsLHSMask(), llvm::SelectionDAGBuilder::EmitBranchForMergedCondition(), ExtractEquivalentCondition(), llvm::InstCombiner::FoldAllocaCmp(), llvm::InstCombiner::FoldAndOfFCmps(), llvm::InstCombiner::FoldAndOfICmps(), llvm::InstCombiner::FoldCmpLoadFromIndexedGlobal(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::InstCombiner::FoldICmpCstShlCst(), llvm::InstCombiner::FoldICmpCstShrCst(), llvm::InstCombiner::FoldICmpDivCst(), llvm::InstCombiner::FoldICmpShrCst(), foldLogOpOfMaskedICmps(), llvm::InstCombiner::FoldOrOfFCmps(), llvm::InstCombiner::FoldOrOfICmps(), foldSelectICmpAndOr(), llvm::getICmpCode(), getInversePredicate(), getSignedPredicate(), getSwappedPredicate(), getValueFromFromCondition(), handleBranchExpect(), llvm::FCmpInst::isCommutative(), llvm::FCmpInst::isEquality(), isFalseWhenEqual(), isFPPredicate(), isIntPredicate(), isSameCompare(), isSigned(), isTrueWhenEqual(), isUnsigned(), matchCondition(), llvm::matchSelectPattern(), needsLFTR(), llvm::FastISel::optimizeCmpPredicate(), OptimizeGlobalAddressOfMalloc(), ProcessUMulZExtIdiom(), llvm::InstCombiner::replacedSelectWithOperand(), reuseTableCompare(), llvm::InstCombiner::simplifyRangeCheck(), SinkCmpExpression(), TryToSimplifyUncondBranchWithICmpInIt(), llvm::Interpreter::visitFCmpInst(), llvm::InstCombiner::visitFCmpInst(), llvm::Interpreter::visitICmpInst(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithCastAndCast(), and llvm::InstCombiner::visitICmpInstWithInstAndIntCst().

For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert.

Returns:
the signed version of the unsigned predicate pred. return the signed version of a predicate

Reimplemented in llvm::ICmpInst.

Definition at line 3513 of file Instructions.cpp.

References ICMP_SGE, ICMP_SGT, ICMP_SLE, ICMP_SLT, ICMP_UGE, ICMP_UGT, ICMP_ULE, ICMP_ULT, isUnsigned(), and llvm_unreachable.

For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert.

Returns:
the signed version of the predicate for this instruction (which has to be an unsigned predicate). return the signed version of a predicate

Definition at line 1045 of file InstrTypes.h.

References getPredicate().

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. Return the predicate as if the operands were swapped

Definition at line 999 of file InstrTypes.h.

References getPredicate().

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

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

Return the predicate as if the operands were swapped.

Definition at line 3483 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, llvm_unreachable, and pred.

This is just a convenience that dispatches to the subclasses.

Determine if this CmpInst is commutative.

Reimplemented from llvm::Instruction.

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

Definition at line 3346 of file Instructions.cpp.

This is just a convenience that dispatches to the subclasses.

Determine if this is an equals/not equals predicate.

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

Definition at line 3352 of file Instructions.cpp.

Referenced by llvm::matchSelectPattern().

This is just a convenience.

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

Definition at line 1057 of file InstrTypes.h.

References getPredicate().

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

bool CmpInst::isFalseWhenEqual ( Predicate  predicate) [static]

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

Definition at line 3572 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 968 of file InstrTypes.h.

References FIRST_FCMP_PREDICATE, and LAST_FCMP_PREDICATE.

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

Definition at line 976 of file InstrTypes.h.

References getPredicate(), and isFPPredicate().

Referenced by isFPPredicate(), matchSelectPattern(), and SimplifyFCmpInst().

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

Definition at line 972 of file InstrTypes.h.

References FIRST_ICMP_PREDICATE, and LAST_ICMP_PREDICATE.

bool llvm::CmpInst::isIntPredicate ( ) const [inline]
bool CmpInst::isOrdered ( Predicate  predicate) [static]

Determine if the predicate is an ordered operation.

Definition at line 3546 of file Instructions.cpp.

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

Referenced by matchSelectPattern(), and SimplifyFCmpInst().

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

Determine if the predicate is an signed operation.

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

Definition at line 3538 of file Instructions.cpp.

References ICMP_SGE, ICMP_SGT, ICMP_SLE, and ICMP_SLT.

bool CmpInst::isTrueWhenEqual ( Predicate  predicate) [static]

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

Definition at line 3564 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 ( Predicate  predicate) [static]

Determine if the predicate is an unordered operation.

Definition at line 3555 of file Instructions.cpp.

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

Referenced by llvm::ConstantFoldCompareInstruction(), and 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 1032 of file InstrTypes.h.

References getPredicate().

Referenced by getSignedPredicate(), lookThroughCast(), SimplifyICmpInst(), simplifyUnsignedRangeCheck(), llvm::InstCombiner::visitICmpInst(), and llvm::InstCombiner::visitICmpInstWithInstAndIntCst().

bool CmpInst::isUnsigned ( Predicate  predicate) [static]

Determine if the predicate is an unsigned operation.

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

Definition at line 3530 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  Size) [inline]

Allocate a User with an operand pointer co-allocated.

This is used for subclasses which need to allocate a variable number of operands, ie, 'hung off uses'.

Reimplemented from llvm::User.

Definition at line 935 of file InstrTypes.h.

References llvm::User::operator new().

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

This is just a convenience that dispatches to the subclasses.

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

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

Definition at line 3339 of file Instructions.cpp.


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