LLVM 22.0.0git
llvm::CmpPredicate Class Reference

An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign information. More...

#include "llvm/IR/CmpPredicate.h"

Public Member Functions

 CmpPredicate ()
 Default constructor.
 CmpPredicate (CmpInst::Predicate Pred, bool HasSameSign=false)
 Constructed implictly with a either Predicate and samesign information, or just a Predicate, dropping samesign information.
 operator CmpInst::Predicate () const
 Implictly converts to the underlying Predicate, dropping samesign information.
bool hasSameSign () const
 Query samesign information, for optimizations.
CmpInst::Predicate dropSameSign () const
 Drops samesign information.
LLVM_ABI CmpInst::Predicate getPreferredSignedPredicate () const
 Attempts to return a signed CmpInst::Predicate from the CmpPredicate.
bool operator== (CmpInst::Predicate P) const
 An operator== on the underlying Predicate.
bool operator!= (CmpInst::Predicate P) const
bool operator== (CmpPredicate) const =delete
 There is no operator== defined on CmpPredicate.
bool operator!= (CmpPredicate) const =delete

Static Public Member Functions

static LLVM_ABI std::optional< CmpPredicategetMatching (CmpPredicate A, CmpPredicate B)
 Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if they match.
static LLVM_ABI CmpPredicate get (const CmpInst *Cmp)
 Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
static LLVM_ABI CmpPredicate getSwapped (CmpPredicate P)
 Get the swapped predicate of a CmpPredicate.
static LLVM_ABI CmpPredicate getSwapped (const CmpInst *Cmp)
 Get the swapped predicate of a CmpInst.

Detailed Description

An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign information.

Some functions in ICmpInst construct and return this type in place of a Predicate.

Definition at line 23 of file CmpPredicate.h.

Constructor & Destructor Documentation

◆ CmpPredicate() [1/2]

llvm::CmpPredicate::CmpPredicate ( )
inline

Default constructor.

Definition at line 29 of file CmpPredicate.h.

Referenced by get(), getMatching(), getSwapped(), getSwapped(), operator!=(), and operator==().

◆ CmpPredicate() [2/2]

llvm::CmpPredicate::CmpPredicate ( CmpInst::Predicate Pred,
bool HasSameSign = false )
inline

Constructed implictly with a either Predicate and samesign information, or just a Predicate, dropping samesign information.

Definition at line 33 of file CmpPredicate.h.

References assert(), and llvm::CmpInst::isIntPredicate().

Member Function Documentation

◆ dropSameSign()

CmpInst::Predicate llvm::CmpPredicate::dropSameSign ( ) const
inline

Drops samesign information.

This is used when the samesign information should be dropped explicitly.

Definition at line 47 of file CmpPredicate.h.

Referenced by llvm::ScalarEvolution::isBasicBlockEntryGuardedByCond(), and isImpliedCondCommonOperandWithCR().

◆ get()

◆ getMatching()

std::optional< CmpPredicate > CmpPredicate::getMatching ( CmpPredicate A,
CmpPredicate B )
static

Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if they match.

An alternative to operator==.

For example, samesign ult + samesign ult -> samesign ult samesign ult + ult -> ult samesign ult + slt -> slt ult + ult -> ult ult + slt -> std::nullopt

Definition at line 4017 of file Instructions.cpp.

References A(), B(), CmpPredicate(), llvm::ICmpInst::getFlippedSignednessPredicate(), and llvm::CmpInst::isFPPredicate().

Referenced by llvm::InstCombinerImpl::foldSelectOpOp(), hoistMinMax(), isImpliedCondICmps(), isImpliedTrueByMatchingCmp(), llvm::PatternMatch::SpecificCmpClass_match< LHS_t, RHS_t, Class, Commutable >::match(), and llvm::VPlanPatternMatch::SpecificCmp_match< Op0_t, Op1_t, Opcodes >::match().

◆ getPreferredSignedPredicate()

CmpInst::Predicate CmpPredicate::getPreferredSignedPredicate ( ) const

Attempts to return a signed CmpInst::Predicate from the CmpPredicate.

If the CmpPredicate has samesign, return ICmpInst::getSignedPredicate, dropping samesign information. Otherwise, return the predicate, dropping samesign information.

Definition at line 4032 of file Instructions.cpp.

References llvm::ICmpInst::getSignedPredicate().

Referenced by isImpliedCondICmps().

◆ getSwapped() [1/2]

◆ getSwapped() [2/2]

CmpPredicate CmpPredicate::getSwapped ( const CmpInst * Cmp)
static

Get the swapped predicate of a CmpInst.

Definition at line 4046 of file Instructions.cpp.

References CmpPredicate(), get(), and getSwapped().

◆ hasSameSign()

bool llvm::CmpPredicate::hasSameSign ( ) const
inline

Query samesign information, for optimizations.

Definition at line 43 of file CmpPredicate.h.

Referenced by isImpliedCondCommonOperandWithCR(), isImpliedTrueByMatchingCmp(), and llvm::isKnownInversion().

◆ operator CmpInst::Predicate()

llvm::CmpPredicate::operator CmpInst::Predicate ( ) const
inline

Implictly converts to the underlying Predicate, dropping samesign information.

Definition at line 40 of file CmpPredicate.h.

◆ operator!=() [1/2]

bool llvm::CmpPredicate::operator!= ( CmpInst::Predicate P) const
inline

Definition at line 69 of file CmpPredicate.h.

References P.

◆ operator!=() [2/2]

bool llvm::CmpPredicate::operator!= ( CmpPredicate ) const
delete

References CmpPredicate(), LLVM_ABI, and P.

◆ operator==() [1/2]

bool llvm::CmpPredicate::operator== ( CmpInst::Predicate P) const
inline

An operator== on the underlying Predicate.

Definition at line 68 of file CmpPredicate.h.

References P.

◆ operator==() [2/2]

bool llvm::CmpPredicate::operator== ( CmpPredicate ) const
delete

There is no operator== defined on CmpPredicate.

Use getMatching instead to get the canonicalized matching CmpPredicate.

References CmpPredicate().


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