LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
InstCombineCompares.cpp File Reference
#include "InstCombine.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/PatternMatch.h"
#include "llvm/Target/TargetLibraryInfo.h"
Include dependency graph for InstCombineCompares.cpp:

Go to the source code of this file.

Functions

static ConstantIntgetOne (Constant *C)
 
static ConstantAddOne (Constant *C)
 AddOne - Add one to a ConstantInt. More...
 
static ConstantSubOne (Constant *C)
 SubOne - Subtract one from a ConstantInt. More...
 
static ConstantIntExtractElement (Constant *V, Constant *Idx)
 
static bool HasAddOverflow (ConstantInt *Result, ConstantInt *In1, ConstantInt *In2, bool IsSigned)
 
static bool AddWithOverflow (Constant *&Result, Constant *In1, Constant *In2, bool IsSigned=false)
 
static bool HasSubOverflow (ConstantInt *Result, ConstantInt *In1, ConstantInt *In2, bool IsSigned)
 
static bool SubWithOverflow (Constant *&Result, Constant *In1, Constant *In2, bool IsSigned=false)
 
static bool isSignBitCheck (ICmpInst::Predicate pred, ConstantInt *RHS, bool &TrueIfSigned)
 
static bool isSignTest (ICmpInst::Predicate &pred, const ConstantInt *RHS)
 
static bool isHighOnes (const ConstantInt *CI)
 
static void ComputeSignedMinMaxValuesFromKnownBits (const APInt &KnownZero, const APInt &KnownOne, APInt &Min, APInt &Max)
 
static void ComputeUnsignedMinMaxValuesFromKnownBits (const APInt &KnownZero, const APInt &KnownOne, APInt &Min, APInt &Max)
 
static ValueEvaluateGEPOffsetExpression (User *GEP, InstCombiner &IC)
 
static InstructionProcessUGT_ADDCST_ADD (ICmpInst &I, Value *A, Value *B, ConstantInt *CI2, ConstantInt *CI1, InstCombiner &IC)
 
static InstructionProcessUAddIdiom (Instruction &I, Value *OrigAddV, InstCombiner &IC)
 
static APInt DemandedBitsLHSMask (ICmpInst &I, unsigned BitWidth, bool isSignCheck)
 
static bool swapMayExposeCSEOpportunities (const Value *Op0, const Value *Op1)
 Check if the order of Op0 and Op1 as operand in an ICmpInst should be swapped. The descision is based on how many times these two operands are reused as subtract operands and their positions in those instructions. The rational is that several architectures use the same instruction for both subtract and cmp, thus it is better if the order of those operands match. More...
 

Function Documentation

static Constant* AddOne ( Constant C)
static
static bool AddWithOverflow ( Constant *&  Result,
Constant In1,
Constant In2,
bool  IsSigned = false 
)
static

AddWithOverflow - Compute Result = In1+In2, returning true if the result overflowed for this type.

Definition at line 57 of file InstCombineCompares.cpp.

References ExtractElement(), llvm::ConstantInt::get(), llvm::ConstantExpr::getAdd(), llvm::Value::getContext(), llvm::Type::getInt32Ty(), llvm::Value::getType(), and HasAddOverflow().

Referenced by llvm::InstCombiner::FoldICmpDivCst().

static void ComputeSignedMinMaxValuesFromKnownBits ( const APInt KnownZero,
const APInt KnownOne,
APInt Min,
APInt Max 
)
static

ComputeSignedMinMaxValuesFromKnownBits - Given a signed integer type and a set of known zero and one bits, compute the maximum and minimum values that could have the specified known zero and known one bits, returning them in min/max.

Definition at line 177 of file InstCombineCompares.cpp.

References llvm::APInt::clearBit(), llvm::APInt::getBitWidth(), and llvm::APInt::setBit().

Referenced by llvm::InstCombiner::visitICmpInst().

static void ComputeUnsignedMinMaxValuesFromKnownBits ( const APInt KnownZero,
const APInt KnownOne,
APInt Min,
APInt Max 
)
static

Definition at line 201 of file InstCombineCompares.cpp.

References llvm::APInt::getBitWidth().

Referenced by llvm::InstCombiner::visitICmpInst().

static APInt DemandedBitsLHSMask ( ICmpInst I,
unsigned  BitWidth,
bool  isSignCheck 
)
static
static Value* EvaluateGEPOffsetExpression ( User GEP,
InstCombiner IC 
)
static

EvaluateGEPOffsetExpression - Return a value that can be used to compare the offset implied by a GEP to zero. For example, if we have &A[i], we want to return 'i' for "icmp ne i, 0". Note that, in general, indices can be complex, and scales are involved. The above expression would also be legal to codegen as "icmp ne (i*4), 0" (assuming A is a pointer to i32). This later form is less amenable to optimization though, and we are allowed to generate the first by knowing that pointer arithmetic doesn't overflow.

If we can't emit an optimized form for this expression, this returns null.

Definition at line 514 of file InstCombineCompares.cpp.

References llvm::InstCombiner::Builder, llvm::IRBuilder< preserveNames, T, Inserter >::CreateAdd(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateIntCast(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateTrunc(), llvm::dyn_cast(), llvm::gep_type_begin(), llvm::ConstantInt::get(), llvm::InstCombiner::getDataLayout(), llvm::StructLayout::getElementOffset(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::Type::getIntegerBitWidth(), llvm::DataLayout::getIntPtrType(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::ConstantInt::getSExtValue(), llvm::DataLayout::getStructLayout(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::ConstantInt::getZExtValue(), llvm::ConstantInt::isZero(), and TD.

Referenced by llvm::InstCombiner::FoldGEPICmp().

static ConstantInt* ExtractElement ( Constant V,
Constant Idx 
)
static
static ConstantInt* getOne ( Constant C)
static
static bool HasAddOverflow ( ConstantInt Result,
ConstantInt In1,
ConstantInt In2,
bool  IsSigned 
)
static
static bool HasSubOverflow ( ConstantInt Result,
ConstantInt In1,
ConstantInt In2,
bool  IsSigned 
)
static
static bool isHighOnes ( const ConstantInt CI)
static
static bool isSignBitCheck ( ICmpInst::Predicate  pred,
ConstantInt RHS,
bool TrueIfSigned 
)
static

isSignBitCheck - Given an exploded icmp instruction, return true if the comparison only checks the sign bit. If it only checks the sign bit, set TrueIfSigned if the result of the comparison is true when the input value is signed.

Definition at line 117 of file InstCombineCompares.cpp.

References llvm::ConstantInt::getValue(), llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::Constant::isAllOnesValue(), llvm::ConstantInt::isMaxValue(), llvm::APInt::isSignBit(), and llvm::ConstantInt::isZero().

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

static bool isSignTest ( ICmpInst::Predicate &  pred,
const ConstantInt RHS 
)
static

Returns true if the exploded icmp can be expressed as a signed comparison to zero and updates the predicate accordingly. The signedness of the comparison is preserved.

Definition at line 145 of file InstCombineCompares.cpp.

References llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::Constant::isAllOnesValue(), llvm::ConstantInt::isOne(), llvm::ICmpInst::isRelational(), llvm::CmpInst::isSigned(), and llvm::ConstantInt::isZero().

Referenced by llvm::InstCombiner::visitICmpInstWithInstAndIntCst().

static Instruction* ProcessUAddIdiom ( Instruction I,
Value OrigAddV,
InstCombiner IC 
)
static
static Instruction* ProcessUGT_ADDCST_ADD ( ICmpInst I,
Value A,
Value B,
ConstantInt CI2,
ConstantInt CI1,
InstCombiner IC 
)
static
static Constant* SubOne ( Constant C)
static
static bool SubWithOverflow ( Constant *&  Result,
Constant In1,
Constant In2,
bool  IsSigned = false 
)
static

SubWithOverflow - Compute Result = In1-In2, returning true if the result overflowed for this type.

Definition at line 92 of file InstCombineCompares.cpp.

References ExtractElement(), llvm::ConstantInt::get(), llvm::Value::getContext(), llvm::Type::getInt32Ty(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), and HasSubOverflow().

Referenced by llvm::InstCombiner::FoldICmpDivCst().

static bool swapMayExposeCSEOpportunities ( const Value Op0,
const Value Op1 
)
static

Check if the order of Op0 and Op1 as operand in an ICmpInst should be swapped. The descision is based on how many times these two operands are reused as subtract operands and their positions in those instructions. The rational is that several architectures use the same instruction for both subtract and cmp, thus it is better if the order of those operands match.

Returns
true if Op0 and Op1 should be swapped.

Definition at line 2049 of file InstCombineCompares.cpp.

References llvm::dyn_cast(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Type::isPointerTy(), llvm::Value::use_begin(), and llvm::Value::use_end().

Referenced by llvm::InstCombiner::visitICmpInst().