LLVM API Documentation

Defines | Enumerations | Functions
InstructionSimplify.cpp File Reference
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ValueHandle.h"
Include dependency graph for InstructionSimplify.cpp:

Go to the source code of this file.

Defines

#define DEBUG_TYPE   "instsimplify"

Enumerations

enum  { RecursionLimit = 3 }

Functions

 STATISTIC (NumExpand,"Number of expansions")
 STATISTIC (NumReassoc,"Number of reassociations")
static ValueSimplifyAndInst (Value *, Value *, const Query &, unsigned)
static ValueSimplifyBinOp (unsigned, Value *, Value *, const Query &, unsigned)
static ValueSimplifyCmpInst (unsigned, Value *, Value *, const Query &, unsigned)
static ValueSimplifyOrInst (Value *, Value *, const Query &, unsigned)
static ValueSimplifyXorInst (Value *, Value *, const Query &, unsigned)
static ValueSimplifyTruncInst (Value *, Type *, const Query &, unsigned)
static ConstantgetFalse (Type *Ty)
static ConstantgetTrue (Type *Ty)
static bool isSameCompare (Value *V, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
 isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
static bool ValueDominatesPHI (Value *V, PHINode *P, const DominatorTree *DT)
 ValueDominatesPHI - Does the given value dominate the specified phi node?
static ValueExpandBinOp (unsigned Opcode, Value *LHS, Value *RHS, unsigned OpcToExpand, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyAssociativeBinOp (unsigned Opc, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
static ValueThreadBinOpOverSelect (unsigned Opcode, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
static ValueThreadCmpOverSelect (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
static ValueThreadBinOpOverPHI (unsigned Opcode, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
static ValueThreadCmpOverPHI (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyAddInst (Value *Op0, Value *Op1, bool isNSW, bool isNUW, const Query &Q, unsigned MaxRecurse)
static ConstantstripAndComputeConstantOffsets (const DataLayout *DL, Value *&V, bool AllowNonInbounds=false)
 Compute the base pointer and cumulative constant offsets for V.
static ConstantcomputePointerDifference (const DataLayout *DL, Value *LHS, Value *RHS)
 Compute the constant difference between two pointer values. If the difference is not a constant, returns zero.
static ValueSimplifySubInst (Value *Op0, Value *Op1, bool isNSW, bool isNUW, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyFAddInst (Value *Op0, Value *Op1, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyFSubInst (Value *Op0, Value *Op1, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyFMulInst (Value *Op0, Value *Op1, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse)
 Given the operands for an FMul, see if we can fold the result.
static ValueSimplifyMulInst (Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyDiv (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifySDivInst (Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyUDivInst (Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyFDivInst (Value *Op0, Value *Op1, const Query &Q, unsigned)
static ValueSimplifyRem (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifySRemInst (Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyURemInst (Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyFRemInst (Value *Op0, Value *Op1, const Query &, unsigned)
static bool isUndefShift (Value *Amount)
 isUndefShift - Returns true if a shift by Amount always yields undef.
static ValueSimplifyShift (unsigned Opcode, Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyShlInst (Value *Op0, Value *Op1, bool isNSW, bool isNUW, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyLShrInst (Value *Op0, Value *Op1, bool isExact, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyAShrInst (Value *Op0, Value *Op1, bool isExact, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyAndOfICmps (ICmpInst *Op0, ICmpInst *Op1)
static ValueSimplifyOrOfICmps (ICmpInst *Op0, ICmpInst *Op1)
static TypeGetCompareTy (Value *Op)
static ValueExtractEquivalentCondition (Value *V, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
static ConstantcomputePointerICmp (const DataLayout *DL, const TargetLibraryInfo *TLI, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
static ValueSimplifyICmpInst (unsigned Predicate, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyFCmpInst (unsigned Predicate, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
static ValueSimplifySelectInst (Value *CondVal, Value *TrueVal, Value *FalseVal, const Query &Q, unsigned MaxRecurse)
static ValueSimplifyGEPInst (ArrayRef< Value * > Ops, const Query &Q, unsigned)
static ValueSimplifyInsertValueInst (Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Query &Q, unsigned)
static ValueSimplifyPHINode (PHINode *PN, const Query &Q)
 SimplifyPHINode - See if we can fold the given phi. If not, returns null.
static bool IsIdempotent (Intrinsic::ID ID)
template<typename IterTy >
static ValueSimplifyIntrinsic (Intrinsic::ID IID, IterTy ArgBegin, IterTy ArgEnd, const Query &Q, unsigned MaxRecurse)
template<typename IterTy >
static ValueSimplifyCall (Value *V, IterTy ArgBegin, IterTy ArgEnd, const Query &Q, unsigned MaxRecurse)
static bool replaceAndRecursivelySimplifyImpl (Instruction *I, Value *SimpleV, const DataLayout *DL, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionTracker *AT)
 Implementation of recursive simplification through an instructions uses.

Define Documentation

#define DEBUG_TYPE   "instsimplify"

Definition at line 37 of file InstructionSimplify.cpp.


Enumeration Type Documentation

anonymous enum
Enumerator:
RecursionLimit 

Definition at line 39 of file InstructionSimplify.cpp.


Function Documentation

static Constant* computePointerDifference ( const DataLayout DL,
Value LHS,
Value RHS 
) [static]

Compute the constant difference between two pointer values. If the difference is not a constant, returns zero.

Definition at line 645 of file InstructionSimplify.cpp.

References llvm::ConstantExpr::getSub(), and stripAndComputeConstantOffsets().

Referenced by SimplifySubInst().

static Constant* computePointerICmp ( const DataLayout DL,
const TargetLibraryInfo TLI,
CmpInst::Predicate  Pred,
Value LHS,
Value RHS 
) [static]
static Value* ExpandBinOp ( unsigned  Opcode,
Value LHS,
Value RHS,
unsigned  OpcToExpand,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

ExpandBinOp - Simplify "A op (B op' C)" by distributing op over op', turning it into "(A op B) op' (A op C)". Here "op" is given by Opcode and "op'" is given by OpcodeToExpand, while "A" corresponds to LHS and "B op' C" to RHS. Also performs the transform "(A op' B) op C" -> "(A op C) op' (B op C)". Returns the simplified value, or null if no simplification was performed.

Definition at line 134 of file InstructionSimplify.cpp.

References llvm::ARM_PROC::A, llvm::CallingConv::C, llvm::Instruction::isCommutative(), and llvm::SimplifyBinOp().

Referenced by SimplifyAndInst(), SimplifyMulInst(), and SimplifyOrInst().

static Value* ExtractEquivalentCondition ( Value V,
CmpInst::Predicate  Pred,
Value LHS,
Value RHS 
) [static]

ExtractEquivalentCondition - Rummage around inside V looking for something equivalent to the comparison "LHS Pred RHS". Return such a value if found, otherwise return null. Helper function for analyzing max/min idioms.

Definition at line 1825 of file InstructionSimplify.cpp.

References llvm::dyn_cast(), llvm::SelectInst::getCondition(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), and llvm::CmpInst::getSwappedPredicate().

Referenced by SimplifyICmpInst().

static Type* GetCompareTy ( Value Op) [static]
static Constant* getFalse ( Type Ty) [static]

getFalse - For a boolean type, or a vector of boolean type, return false, or a vector with every element false, as appropriate for the type.

Definition at line 70 of file InstructionSimplify.cpp.

References llvm::Constant::getNullValue(), llvm::Type::getScalarType(), and llvm::Type::isIntegerTy().

Referenced by SimplifyAndOfICmps(), SimplifyFCmpInst(), SimplifyICmpInst(), ThreadCmpOverSelect(), and TryToSimplifyUncondBranchWithICmpInIt().

static Constant* getTrue ( Type Ty) [static]

getTrue - For a boolean type, or a vector of boolean type, return true, or a vector with every element true, as appropriate for the type.

Definition at line 78 of file InstructionSimplify.cpp.

References llvm::Constant::getAllOnesValue(), llvm::Type::getScalarType(), and llvm::Type::isIntegerTy().

Referenced by computeKnownBits(), getFCmpValue(), SimplifyFCmpInst(), SimplifyICmpInst(), SimplifyOrOfICmps(), ThreadCmpOverSelect(), and TryToSimplifyUncondBranchWithICmpInIt().

static bool IsIdempotent ( Intrinsic::ID  ID) [static]
static bool isSameCompare ( Value V,
CmpInst::Predicate  Pred,
Value LHS,
Value RHS 
) [static]

isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?

Definition at line 85 of file InstructionSimplify.cpp.

References llvm::dyn_cast(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), and llvm::PPC::getSwappedPredicate().

Referenced by ThreadCmpOverSelect().

static bool isUndefShift ( Value Amount) [static]

isUndefShift - Returns true if a shift by Amount always yields undef.

Definition at line 1257 of file InstructionSimplify.cpp.

References llvm::CallingConv::C, llvm::dyn_cast(), llvm::Constant::getAggregateElement(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), and I.

Referenced by SimplifyShift().

static bool replaceAndRecursivelySimplifyImpl ( Instruction I,
Value SimpleV,
const DataLayout DL,
const TargetLibraryInfo TLI,
const DominatorTree DT,
AssumptionTracker AT 
) [static]

Implementation of recursive simplification through an instructions uses.

This is the common implementation of the recursive simplification routines. If we have a pre-simplified value in 'SimpleV', that is forcibly used to replace the instruction 'I'. Otherwise, we simply add 'I' to the list of instructions to process and attempt to simplify it using InstructionSimplify.

This routine returns 'true' only when *it* simplifies something. The passed in simplified value does not count toward this.

Definition at line 3528 of file InstructionSimplify.cpp.

References llvm::Instruction::eraseFromParent(), llvm::Instruction::getParent(), llvm::SetVector< T, SmallVector< T, N >, SmallSet< T, N > >::insert(), llvm::Value::replaceAllUsesWith(), llvm::JumpTable::Simplified, llvm::SimplifyInstruction(), llvm::SetVector< T, SmallVector< T, N >, SmallSet< T, N > >::size(), and llvm::Value::users().

Referenced by llvm::recursivelySimplifyInstruction(), and llvm::replaceAndRecursivelySimplify().

static Value* SimplifyAddInst ( Value Op0,
Value Op1,
bool  isNSW,
bool  isNUW,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value * SimplifyAndInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyAndOfICmps ( ICmpInst Op0,
ICmpInst Op1 
) [static]
static Value* SimplifyAShrInst ( Value Op0,
Value Op1,
bool  isExact,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyAssociativeBinOp ( unsigned  Opc,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifyAssociativeBinOp - Generic simplifications for associative binary operations. Returns the simpler value, or null if none was found.

Definition at line 193 of file InstructionSimplify.cpp.

References llvm::ARM_PROC::A, llvm::CallingConv::C, llvm::dyn_cast(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), and llvm::SimplifyBinOp().

Referenced by SimplifyAddInst(), SimplifyAndInst(), SimplifyBinOp(), SimplifyMulInst(), SimplifyOrInst(), and SimplifyXorInst().

static Value * SimplifyBinOp ( unsigned  Opcode,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
template<typename IterTy >
static Value* SimplifyCall ( Value V,
IterTy  ArgBegin,
IterTy  ArgEnd,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value * SimplifyCmpInst ( unsigned  Predicate,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifyCmpInst - Given operands for a CmpInst, see if we can fold the result.

Definition at line 3278 of file InstructionSimplify.cpp.

References llvm::CmpInst::isIntPredicate(), llvm::SimplifyFCmpInst(), and llvm::SimplifyICmpInst().

static Value* SimplifyDiv ( Instruction::BinaryOps  Opcode,
Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyFAddInst ( Value Op0,
Value Op1,
FastMathFlags  FMF,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyFCmpInst ( unsigned  Predicate,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyFDivInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned   
) [static]
static Value* SimplifyFMulInst ( Value Op0,
Value Op1,
FastMathFlags  FMF,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyFRemInst ( Value Op0,
Value Op1,
const Query &  ,
unsigned   
) [static]
static Value* SimplifyFSubInst ( Value Op0,
Value Op1,
FastMathFlags  FMF,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyGEPInst ( ArrayRef< Value * >  Ops,
const Query &  Q,
unsigned   
) [static]
static Value* SimplifyICmpInst ( unsigned  Predicate,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifyICmpInst - Given operands for an ICmpInst, see if we can fold the result. If not, this returns null.

Definition at line 1998 of file InstructionSimplify.cpp.

References llvm::ARM_PROC::A, llvm::APInt::abs(), llvm::APInt::ashr(), llvm::CmpInst::BAD_ICMP_PREDICATE, llvm::CallingConv::C, llvm::computeKnownBits(), computePointerICmp(), llvm::ComputeSignBit(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantRange::contains(), llvm::APInt::countLeadingOnes(), llvm::APInt::countLeadingZeros(), llvm::APInt::countTrailingZeros(), llvm::dyn_cast(), ExtractEquivalentCondition(), llvm::ConstantInt::get(), llvm::APInt::getAllOnesValue(), llvm::ConstantInt::getBitWidth(), llvm::ConstantExpr::getCast(), GetCompareTy(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), getFalse(), llvm::ConstantExpr::getGetElementPtr(), llvm::ConstantExpr::getICmp(), llvm::ConstantExpr::getIntToPtr(), llvm::CmpInst::getInversePredicate(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarType(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), llvm::ICmpInst::getSignedPredicate(), llvm::PPC::getSwappedPredicate(), llvm::ConstantInt::getTrue(), getTrue(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::ICmpInst::getUnsignedPredicate(), llvm::ConstantInt::getValue(), llvm::BinaryOperator::hasNoSignedWrap(), llvm::BinaryOperator::hasNoUnsignedWrap(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ConstantRange::inverse(), llvm::APInt::isAllOnesValue(), llvm::ConstantRange::isEmptySet(), llvm::ICmpInst::isEquality(), llvm::BinaryOperator::isExact(), llvm::ConstantRange::isFullSet(), llvm::Type::isIntegerTy(), llvm::CmpInst::isIntPredicate(), llvm::isKnownNonZero(), llvm::Constant::isMinSignedValue(), llvm::ConstantInt::isNegative(), llvm::Type::isPointerTy(), llvm::APInt::isPowerOf2(), llvm::APInt::isSignBit(), llvm::CmpInst::isSigned(), llvm::CmpInst::isTrueWhenEqual(), llvm::CmpInst::isUnsigned(), llvm::ConstantInt::isZero(), LI, llvm_unreachable, llvm::LShr, llvm::APInt::lshr(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SMax(), llvm::PatternMatch::m_SMin(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_UMax(), llvm::PatternMatch::m_UMin(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::ICmpInst::makeConstantRange(), llvm::PatternMatch::match(), P, llvm::APInt::sdiv(), llvm::SExt, llvm::APInt::sgt(), llvm::APInt::shl(), llvm::SimplifyICmpInst(), std::swap(), ThreadCmpOverPHI(), ThreadCmpOverSelect(), llvm::Trunc, llvm::APInt::udiv(), llvm::APInt::ult(), and Y.

static Value* SimplifyInsertValueInst ( Value Agg,
Value Val,
ArrayRef< unsigned Idxs,
const Query &  Q,
unsigned   
) [static]

SimplifyInsertValueInst - Given operands for an InsertValueInst, see if we can fold the result. If not, this returns null.

Definition at line 3112 of file InstructionSimplify.cpp.

References llvm::ConstantFoldInsertValueInstruction(), llvm::Value::getType(), llvm::PatternMatch::m_Undef(), and llvm::PatternMatch::match().

template<typename IterTy >
static Value* SimplifyIntrinsic ( Intrinsic::ID  IID,
IterTy  ArgBegin,
IterTy  ArgEnd,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

Definition at line 3310 of file InstructionSimplify.cpp.

References IsIdempotent().

Referenced by SimplifyCall().

static Value* SimplifyLShrInst ( Value Op0,
Value Op1,
bool  isExact,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifyLShrInst - Given operands for an LShr, see if we can fold the result. If not, this returns null.

Definition at line 1349 of file InstructionSimplify.cpp.

References llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::LShr, llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), SimplifyShift(), and llvm::X.

static Value* SimplifyMulInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value * SimplifyOrInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifyOrOfICmps ( ICmpInst Op0,
ICmpInst Op1 
) [static]
static Value* SimplifyPHINode ( PHINode PN,
const Query &  Q 
) [static]

SimplifyPHINode - See if we can fold the given phi. If not, returns null.

Definition at line 3152 of file InstructionSimplify.cpp.

References llvm::UndefValue::get(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::Value::getType(), and ValueDominatesPHI().

Referenced by llvm::SimplifyInstruction().

static Value* SimplifyRem ( Instruction::BinaryOps  Opcode,
Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifySDivInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifySDivInst - Given operands for an SDiv, see if we can fold the result. If not, this returns null.

Definition at line 1077 of file InstructionSimplify.cpp.

References SimplifyDiv().

static Value* SimplifySelectInst ( Value CondVal,
Value TrueVal,
Value FalseVal,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifySelectInst - Given operands for a SelectInst, see if we can fold the result. If not, this returns null.

Definition at line 2982 of file InstructionSimplify.cpp.

static Value* SimplifyShift ( unsigned  Opcode,
Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifyShift - Given operands for an Shl, LShr or AShr, see if we can fold the result. If not, this returns null.

Definition at line 1285 of file InstructionSimplify.cpp.

References llvm::ConstantFoldInstOperands(), llvm::UndefValue::get(), llvm::Value::getType(), isUndefShift(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), ThreadBinOpOverPHI(), and ThreadBinOpOverSelect().

Referenced by SimplifyAShrInst(), SimplifyLShrInst(), and SimplifyShlInst().

static Value* SimplifyShlInst ( Value Op0,
Value Op1,
bool  isNSW,
bool  isNUW,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value* SimplifySRemInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifySRemInst - Given operands for an SRem, see if we can fold the result. If not, this returns null.

Definition at line 1198 of file InstructionSimplify.cpp.

References SimplifyRem().

static Value* SimplifySubInst ( Value Op0,
Value Op1,
bool  isNSW,
bool  isNUW,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
static Value * SimplifyTruncInst ( Value Op,
Type Ty,
const Query &  Q,
unsigned   
) [static]
static Value* SimplifyUDivInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifyUDivInst - Given operands for a UDiv, see if we can fold the result. If not, this returns null.

Definition at line 1096 of file InstructionSimplify.cpp.

References SimplifyDiv().

static Value* SimplifyURemInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

SimplifyURemInst - Given operands for a URem, see if we can fold the result. If not, this returns null.

Definition at line 1217 of file InstructionSimplify.cpp.

References SimplifyRem().

static Value * SimplifyXorInst ( Value Op0,
Value Op1,
const Query &  Q,
unsigned  MaxRecurse 
) [static]
STATISTIC ( NumExpand  ,
"Number of expansions"   
)
STATISTIC ( NumReassoc  ,
"Number of reassociations"   
)
static Constant* stripAndComputeConstantOffsets ( const DataLayout DL,
Value *&  V,
bool  AllowNonInbounds = false 
) [static]

Compute the base pointer and cumulative constant offsets for V.

This strips all constant offsets off of V, leaving it the base pointer, and accumulates the total constant offset applied in the returned constant. It returns 0 if V is not a pointer, and returns the constant '0' if there are no constant offsets applied.

This is very similar to GetPointerBaseWithConstantOffset except it doesn't follow non-inbounds geps. This allows it to remain usable for icmp ult/etc. folding.

Definition at line 600 of file InstructionSimplify.cpp.

References llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::Value::getContext(), llvm::Type::getIntegerBitWidth(), llvm::DataLayout::getIntPtrType(), llvm::APInt::getNullValue(), llvm::Operator::getOpcode(), llvm::Type::getScalarType(), llvm::ConstantVector::getSplat(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Type::isPointerTy(), and llvm::Type::isVectorTy().

Referenced by computePointerDifference(), and computePointerICmp().

static Value* ThreadBinOpOverPHI ( unsigned  Opcode,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

ThreadBinOpOverPHI - In the case of a binary operation with an operand that is a PHI instruction, try to simplify the binop by seeing whether evaluating it on the incoming phi values yields the same result for every value. If so returns the common value, otherwise returns null.

Definition at line 446 of file InstructionSimplify.cpp.

References llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::SimplifyBinOp(), and ValueDominatesPHI().

Referenced by SimplifyAndInst(), SimplifyBinOp(), SimplifyDiv(), SimplifyMulInst(), SimplifyOrInst(), SimplifyRem(), and SimplifyShift().

static Value* ThreadBinOpOverSelect ( unsigned  Opcode,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

ThreadBinOpOverSelect - In the case of a binary operation with a select instruction as an operand, try to simplify the binop by seeing whether evaluating it on both branches of the select results in the same value. Returns the common value if so, otherwise returns null.

Definition at line 292 of file InstructionSimplify.cpp.

References llvm::dyn_cast(), llvm::SelectInst::getFalseValue(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::SelectInst::getTrueValue(), llvm::Instruction::isCommutative(), llvm::JumpTable::Simplified, and llvm::SimplifyBinOp().

Referenced by SimplifyAndInst(), SimplifyBinOp(), SimplifyDiv(), SimplifyMulInst(), SimplifyOrInst(), SimplifyRem(), and SimplifyShift().

static Value* ThreadCmpOverPHI ( CmpInst::Predicate  Pred,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

ThreadCmpOverPHI - In the case of a comparison with a PHI instruction, try try to simplify the comparison by seeing whether comparing with all of the incoming phi values yields the same result every time. If so returns the common result, otherwise returns null.

Definition at line 489 of file InstructionSimplify.cpp.

References llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::PPC::getSwappedPredicate(), llvm::SimplifyCmpInst(), std::swap(), and ValueDominatesPHI().

Referenced by SimplifyFCmpInst(), and SimplifyICmpInst().

static Value* ThreadCmpOverSelect ( CmpInst::Predicate  Pred,
Value LHS,
Value RHS,
const Query &  Q,
unsigned  MaxRecurse 
) [static]

ThreadCmpOverSelect - In the case of a comparison with a select instruction, try to simplify the comparison by seeing whether both branches of the select result in the same value. Returns the common value if so, otherwise returns null.

Definition at line 364 of file InstructionSimplify.cpp.

References llvm::FCmp, llvm::Constant::getAllOnesValue(), llvm::SelectInst::getCondition(), getFalse(), llvm::SelectInst::getFalseValue(), llvm::PPC::getSwappedPredicate(), getTrue(), llvm::SelectInst::getTrueValue(), llvm::Value::getType(), isSameCompare(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::SimplifyAndInst(), llvm::SimplifyCmpInst(), llvm::SimplifyOrInst(), llvm::SimplifyXorInst(), and std::swap().

Referenced by SimplifyFCmpInst(), and SimplifyICmpInst().

static bool ValueDominatesPHI ( Value V,
PHINode P,
const DominatorTree DT 
) [static]