LLVM  3.7.0
Public Types | Public Member Functions | Public Attributes | List of all members
llvm::InstCombiner Class Reference

The core instruction combiner logic. More...

#include <InstCombineInternal.h>

Inheritance diagram for llvm::InstCombiner:
[legend]
Collaboration diagram for llvm::InstCombiner:
[legend]

Public Types

typedef IRBuilder< true,
TargetFolder,
InstCombineIRInserter
BuilderTy
 An IRBuilder that automatically inserts new instructions into the worklist. More...
 

Public Member Functions

 InstCombiner (InstCombineWorklist &Worklist, BuilderTy *Builder, bool MinimizeSize, AliasAnalysis *AA, AssumptionCache *AC, TargetLibraryInfo *TLI, DominatorTree *DT, const DataLayout &DL, LoopInfo *LI)
 
bool run ()
 Run the combiner over the entire worklist until it is empty. More...
 
AssumptionCachegetAssumptionCache () const
 
const DataLayoutgetDataLayout () const
 
DominatorTreegetDominatorTree () const
 
LoopInfogetLoopInfo () const
 
TargetLibraryInfogetTargetLibraryInfo () const
 
InstructionvisitAdd (BinaryOperator &I)
 
InstructionvisitFAdd (BinaryOperator &I)
 
ValueOptimizePointerDifference (Value *LHS, Value *RHS, Type *Ty)
 Optimize pointer differences into the same array into a size. More...
 
InstructionvisitSub (BinaryOperator &I)
 
InstructionvisitFSub (BinaryOperator &I)
 
InstructionvisitMul (BinaryOperator &I)
 
ValuefoldFMulConst (Instruction *FMulOrDiv, Constant *C, Instruction *InsertBefore)
 foldFMulConst() is a helper routine of InstCombiner::visitFMul(). More...
 
InstructionvisitFMul (BinaryOperator &I)
 
InstructionvisitURem (BinaryOperator &I)
 
InstructionvisitSRem (BinaryOperator &I)
 
InstructionvisitFRem (BinaryOperator &I)
 
bool SimplifyDivRemOfSelect (BinaryOperator &I)
 SimplifyDivRemOfSelect - Try to fold a divide or remainder of a select instruction. More...
 
InstructioncommonRemTransforms (BinaryOperator &I)
 
InstructioncommonIRemTransforms (BinaryOperator &I)
 This function implements the transforms common to both integer remainder instructions (urem and srem). More...
 
InstructioncommonDivTransforms (BinaryOperator &I)
 
InstructioncommonIDivTransforms (BinaryOperator &I)
 This function implements the transforms common to both integer division instructions (udiv and sdiv). More...
 
InstructionvisitUDiv (BinaryOperator &I)
 
InstructionvisitSDiv (BinaryOperator &I)
 
InstructionvisitFDiv (BinaryOperator &I)
 
ValuesimplifyRangeCheck (ICmpInst *Cmp0, ICmpInst *Cmp1, bool Inverted)
 Try to fold a signed range checked with lower bound 0 to an unsigned icmp. More...
 
ValueFoldAndOfICmps (ICmpInst *LHS, ICmpInst *RHS)
 FoldAndOfICmps - Fold (icmp)&(icmp) if possible. More...
 
ValueFoldAndOfFCmps (FCmpInst *LHS, FCmpInst *RHS)
 FoldAndOfFCmps - Optimize (fcmp)&(fcmp). More...
 
InstructionvisitAnd (BinaryOperator &I)
 
ValueFoldOrOfICmps (ICmpInst *LHS, ICmpInst *RHS, Instruction *CxtI)
 FoldOrOfICmps - Fold (icmp)|(icmp) if possible. More...
 
ValueFoldOrOfFCmps (FCmpInst *LHS, FCmpInst *RHS)
 FoldOrOfFCmps - Optimize (fcmp)|(fcmp). More...
 
InstructionFoldOrWithConstants (BinaryOperator &I, Value *Op, Value *A, Value *B, Value *C)
 FoldOrWithConstants - This helper function folds: More...
 
InstructionFoldXorWithConstants (BinaryOperator &I, Value *Op, Value *A, Value *B, Value *C)
 This helper function folds: More...
 
InstructionvisitOr (BinaryOperator &I)
 
InstructionvisitXor (BinaryOperator &I)
 
InstructionvisitShl (BinaryOperator &I)
 
InstructionvisitAShr (BinaryOperator &I)
 
InstructionvisitLShr (BinaryOperator &I)
 
InstructioncommonShiftTransforms (BinaryOperator &I)
 
InstructionFoldFCmp_IntToFP_Cst (FCmpInst &I, Instruction *LHSI, Constant *RHSC)
 FoldFCmp_IntToFP_Cst - Fold fcmp ([us]itofp x, cst) if possible. More...
 
InstructionFoldCmpLoadFromIndexedGlobal (GetElementPtrInst *GEP, GlobalVariable *GV, CmpInst &ICI, ConstantInt *AndCst=nullptr)
 FoldCmpLoadFromIndexedGlobal - Called we see this pattern: cmp pred (load (gep GV, ...)), cmpcst where GV is a global variable with a constant initializer. More...
 
InstructionvisitFCmpInst (FCmpInst &I)
 
InstructionvisitICmpInst (ICmpInst &I)
 
InstructionvisitICmpInstWithCastAndCast (ICmpInst &ICI)
 visitICmpInstWithCastAndCast - Handle icmp (cast x to y), (cast/cst). More...
 
InstructionvisitICmpInstWithInstAndIntCst (ICmpInst &ICI, Instruction *LHS, ConstantInt *RHS)
 visitICmpInstWithInstAndIntCst - Handle "icmp (instr, intcst)". More...
 
InstructionFoldICmpDivCst (ICmpInst &ICI, BinaryOperator *DivI, ConstantInt *DivRHS)
 FoldICmpDivCst - Fold "icmp pred, ([su]div X, DivRHS), CmpRHS" where DivRHS and CmpRHS are both known to be integer constants. More...
 
InstructionFoldICmpShrCst (ICmpInst &ICI, BinaryOperator *DivI, ConstantInt *DivRHS)
 FoldICmpShrCst - Handle "icmp(([al]shr X, cst1), cst2)". More...
 
InstructionFoldICmpCstShrCst (ICmpInst &I, Value *Op, Value *A, ConstantInt *CI1, ConstantInt *CI2)
 FoldICmpCstShrCst - Handle "(icmp eq/ne (ashr/lshr const2, A), const1)" -> (icmp eq/ne A, Log2(const2/const1)) -> (icmp eq/ne A, Log2(const2) - Log2(const1)). More...
 
InstructionFoldICmpCstShlCst (ICmpInst &I, Value *Op, Value *A, ConstantInt *CI1, ConstantInt *CI2)
 FoldICmpCstShlCst - Handle "(icmp eq/ne (shl const2, A), const1)" -> (icmp eq/ne A, TrailingZeros(const1) - TrailingZeros(const2)). More...
 
InstructionFoldICmpAddOpCst (Instruction &ICI, Value *X, ConstantInt *CI, ICmpInst::Predicate Pred)
 FoldICmpAddOpCst - Fold "icmp pred (X+CI), X". More...
 
InstructionFoldGEPICmp (GEPOperator *GEPLHS, Value *RHS, ICmpInst::Predicate Cond, Instruction &I)
 FoldGEPICmp - Fold comparisons between a GEP instruction and something else. More...
 
InstructionFoldShiftByConstant (Value *Op0, Constant *Op1, BinaryOperator &I)
 
InstructioncommonCastTransforms (CastInst &CI)
 Implement the transforms common to all CastInst visitors. More...
 
InstructioncommonPointerCastTransforms (CastInst &CI)
 Implement the transforms for cast of pointer (bitcast/ptrtoint) More...
 
InstructionvisitTrunc (TruncInst &CI)
 
InstructionvisitZExt (ZExtInst &CI)
 
InstructionvisitSExt (SExtInst &CI)
 
InstructionvisitFPTrunc (FPTruncInst &CI)
 
InstructionvisitFPExt (CastInst &CI)
 
InstructionvisitFPToUI (FPToUIInst &FI)
 
InstructionvisitFPToSI (FPToSIInst &FI)
 
InstructionvisitUIToFP (CastInst &CI)
 
InstructionvisitSIToFP (CastInst &CI)
 
InstructionvisitPtrToInt (PtrToIntInst &CI)
 
InstructionvisitIntToPtr (IntToPtrInst &CI)
 
InstructionvisitBitCast (BitCastInst &CI)
 
InstructionvisitAddrSpaceCast (AddrSpaceCastInst &CI)
 
InstructionFoldSelectOpOp (SelectInst &SI, Instruction *TI, Instruction *FI)
 FoldSelectOpOp - Here we have (select c, TI, FI), and we know that TI and FI have the same opcode and only one use each. More...
 
InstructionFoldSelectIntoOp (SelectInst &SI, Value *, Value *)
 FoldSelectIntoOp - Try fold the select into one of the operands to facilitate further optimization. More...
 
InstructionFoldSPFofSPF (Instruction *Inner, SelectPatternFlavor SPF1, Value *A, Value *B, Instruction &Outer, SelectPatternFlavor SPF2, Value *C)
 
InstructionFoldItoFPtoI (Instruction &FI)
 
InstructionvisitSelectInst (SelectInst &SI)
 
InstructionvisitSelectInstWithICmp (SelectInst &SI, ICmpInst *ICI)
 
InstructionvisitCallInst (CallInst &CI)
 visitCallInst - CallInst simplification. More...
 
InstructionvisitInvokeInst (InvokeInst &II)
 
InstructionSliceUpIllegalIntegerPHI (PHINode &PN)
 This is an integer PHI and we know that it has an illegal type: see if it is only used by trunc or trunc(lshr) operations. More...
 
InstructionvisitPHINode (PHINode &PN)
 
InstructionvisitGetElementPtrInst (GetElementPtrInst &GEP)
 
InstructionvisitAllocaInst (AllocaInst &AI)
 
InstructionvisitAllocSite (Instruction &FI)
 
InstructionvisitFree (CallInst &FI)
 
InstructionvisitLoadInst (LoadInst &LI)
 
InstructionvisitStoreInst (StoreInst &SI)
 
InstructionvisitBranchInst (BranchInst &BI)
 
InstructionvisitSwitchInst (SwitchInst &SI)
 
InstructionvisitReturnInst (ReturnInst &RI)
 
InstructionvisitInsertValueInst (InsertValueInst &IV)
 Try to find redundant insertvalue instructions, like the following ones: %0 = insertvalue { i8, i32 } undef, i8 x, 0 %1 = insertvalue { i8, i32 } %0, i8 y, 0 Here the second instruction inserts values at the same indices, as the first one, making the first one redundant. More...
 
InstructionvisitInsertElementInst (InsertElementInst &IE)
 
InstructionvisitExtractElementInst (ExtractElementInst &EI)
 
InstructionvisitShuffleVectorInst (ShuffleVectorInst &SVI)
 
InstructionvisitExtractValueInst (ExtractValueInst &EV)
 
InstructionvisitLandingPadInst (LandingPadInst &LI)
 
InstructionvisitInstruction (Instruction &I)
 
bool dominatesAllUses (const Instruction *DI, const Instruction *UI, const BasicBlock *DB) const
 Check that one use is in the same block as the definition and all other uses are in blocks dominated by a given block. More...
 
bool replacedSelectWithOperand (SelectInst *SI, const ICmpInst *Icmp, const unsigned SIOpd)
 True when a select result is replaced by one of its operands in select-icmp sequence. More...
 
InstructionInsertNewInstBefore (Instruction *New, Instruction &Old)
 Inserts an instruction New before instruction Old. More...
 
InstructionInsertNewInstWith (Instruction *New, Instruction &Old)
 Same as InsertNewInstBefore, but also sets the debug loc. More...
 
InstructionReplaceInstUsesWith (Instruction &I, Value *V)
 A combiner-aware RAUW-like routine. More...
 
InstructionCreateOverflowTuple (IntrinsicInst *II, Value *Result, Constant *Overflow)
 Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value. More...
 
InstructionEraseInstFromFunction (Instruction &I)
 Combiner aware instruction erasure. More...
 
void computeKnownBits (Value *V, APInt &KnownZero, APInt &KnownOne, unsigned Depth, Instruction *CxtI) const
 
bool MaskedValueIsZero (Value *V, const APInt &Mask, unsigned Depth=0, Instruction *CxtI=nullptr) const
 
unsigned ComputeNumSignBits (Value *Op, unsigned Depth=0, Instruction *CxtI=nullptr) const
 
void ComputeSignBit (Value *V, bool &KnownZero, bool &KnownOne, unsigned Depth=0, Instruction *CxtI=nullptr) const
 
OverflowResult computeOverflowForUnsignedMul (Value *LHS, Value *RHS, const Instruction *CxtI)
 
OverflowResult computeOverflowForUnsignedAdd (Value *LHS, Value *RHS, const Instruction *CxtI)
 
- Public Member Functions inherited from llvm::InstVisitor< InstCombiner, Instruction * >
void visit (Iterator Start, Iterator End)
 
void visit (Module &M)
 
void visit (Function &F)
 
void visit (BasicBlock &BB)
 
void visit (Module *M)
 
void visit (Function *F)
 
void visit (BasicBlock *BB)
 
Instructionvisit (Instruction *I)
 
Instructionvisit (Instruction &I)
 
void visitModule (Module &M)
 
void visitFunction (Function &F)
 
void visitBasicBlock (BasicBlock &BB)
 
InstructionvisitReturnInst (ReturnInst &I)
 
InstructionvisitBranchInst (BranchInst &I)
 
InstructionvisitSwitchInst (SwitchInst &I)
 
InstructionvisitIndirectBrInst (IndirectBrInst &I)
 
InstructionvisitResumeInst (ResumeInst &I)
 
InstructionvisitUnreachableInst (UnreachableInst &I)
 
InstructionvisitICmpInst (ICmpInst &I)
 
InstructionvisitFCmpInst (FCmpInst &I)
 
InstructionvisitAllocaInst (AllocaInst &I)
 
InstructionvisitLoadInst (LoadInst &I)
 
InstructionvisitStoreInst (StoreInst &I)
 
InstructionvisitAtomicCmpXchgInst (AtomicCmpXchgInst &I)
 
InstructionvisitAtomicRMWInst (AtomicRMWInst &I)
 
InstructionvisitFenceInst (FenceInst &I)
 
InstructionvisitGetElementPtrInst (GetElementPtrInst &I)
 
InstructionvisitPHINode (PHINode &I)
 
InstructionvisitTruncInst (TruncInst &I)
 
InstructionvisitZExtInst (ZExtInst &I)
 
InstructionvisitSExtInst (SExtInst &I)
 
InstructionvisitFPTruncInst (FPTruncInst &I)
 
InstructionvisitFPExtInst (FPExtInst &I)
 
InstructionvisitFPToUIInst (FPToUIInst &I)
 
InstructionvisitFPToSIInst (FPToSIInst &I)
 
InstructionvisitUIToFPInst (UIToFPInst &I)
 
InstructionvisitSIToFPInst (SIToFPInst &I)
 
InstructionvisitPtrToIntInst (PtrToIntInst &I)
 
InstructionvisitIntToPtrInst (IntToPtrInst &I)
 
InstructionvisitBitCastInst (BitCastInst &I)
 
InstructionvisitAddrSpaceCastInst (AddrSpaceCastInst &I)
 
InstructionvisitSelectInst (SelectInst &I)
 
InstructionvisitVAArgInst (VAArgInst &I)
 
InstructionvisitExtractElementInst (ExtractElementInst &I)
 
InstructionvisitInsertElementInst (InsertElementInst &I)
 
InstructionvisitShuffleVectorInst (ShuffleVectorInst &I)
 
InstructionvisitExtractValueInst (ExtractValueInst &I)
 
InstructionvisitInsertValueInst (InsertValueInst &I)
 
InstructionvisitLandingPadInst (LandingPadInst &I)
 
InstructionvisitDbgDeclareInst (DbgDeclareInst &I)
 
InstructionvisitDbgValueInst (DbgValueInst &I)
 
InstructionvisitDbgInfoIntrinsic (DbgInfoIntrinsic &I)
 
InstructionvisitMemSetInst (MemSetInst &I)
 
InstructionvisitMemCpyInst (MemCpyInst &I)
 
InstructionvisitMemMoveInst (MemMoveInst &I)
 
InstructionvisitMemTransferInst (MemTransferInst &I)
 
InstructionvisitMemIntrinsic (MemIntrinsic &I)
 
InstructionvisitVAStartInst (VAStartInst &I)
 
InstructionvisitVAEndInst (VAEndInst &I)
 
InstructionvisitVACopyInst (VACopyInst &I)
 
InstructionvisitIntrinsicInst (IntrinsicInst &I)
 
InstructionvisitCallInst (CallInst &I)
 
InstructionvisitInvokeInst (InvokeInst &I)
 
InstructionvisitCastInst (CastInst &I)
 
InstructionvisitBinaryOperator (BinaryOperator &I)
 
InstructionvisitCmpInst (CmpInst &I)
 
InstructionvisitTerminatorInst (TerminatorInst &I)
 
InstructionvisitUnaryInstruction (UnaryInstruction &I)
 
InstructionvisitCallSite (CallSite CS)
 
void visitInstruction (Instruction &I)
 

Public Attributes

InstCombineWorklistWorklist
 A worklist of the instructions that need to be simplified. More...
 
BuilderTyBuilder
 

Detailed Description

The core instruction combiner logic.

This class provides both the logic to recursively visit instructions and combine them, as well as the pass infrastructure for running this as part of the LLVM pass pipeline.

Definition at line 165 of file InstCombineInternal.h.

Member Typedef Documentation

An IRBuilder that automatically inserts new instructions into the worklist.

Definition at line 174 of file InstCombineInternal.h.

Constructor & Destructor Documentation

llvm::InstCombiner::InstCombiner ( InstCombineWorklist Worklist,
BuilderTy Builder,
bool  MinimizeSize,
AliasAnalysis AA,
AssumptionCache AC,
TargetLibraryInfo TLI,
DominatorTree DT,
const DataLayout DL,
LoopInfo LI 
)
inline

Definition at line 197 of file InstCombineInternal.h.

Member Function Documentation

Instruction * InstCombiner::commonCastTransforms ( CastInst CI)
Instruction* llvm::InstCombiner::commonDivTransforms ( BinaryOperator I)
Instruction * InstCombiner::commonIDivTransforms ( BinaryOperator I)
Instruction * InstCombiner::commonIRemTransforms ( BinaryOperator I)

This function implements the transforms common to both integer remainder instructions (urem and srem).

It is called by the visitors to those integer remainder instructions. Common integer remainder transforms

Definition at line 1341 of file InstCombineMulDivRem.cpp.

References llvm::User::getOperand(), I, llvm::AArch64CC::NV, llvm::User::setOperand(), SI, and simplifyValueKnownNonZero().

Instruction * InstCombiner::commonPointerCastTransforms ( CastInst CI)

Implement the transforms for cast of pointer (bitcast/ptrtoint)

Definition at line 1443 of file InstCombineCasts.cpp.

References GEP, llvm::User::getOperand(), and llvm::User::setOperand().

Instruction* llvm::InstCombiner::commonRemTransforms ( BinaryOperator I)
Instruction * InstCombiner::commonShiftTransforms ( BinaryOperator I)
void llvm::InstCombiner::computeKnownBits ( Value V,
APInt KnownZero,
APInt KnownOne,
unsigned  Depth,
Instruction CxtI 
) const
inline

Definition at line 464 of file InstCombineInternal.h.

References llvm::computeKnownBits(), and llvm::DL.

unsigned llvm::InstCombiner::ComputeNumSignBits ( Value Op,
unsigned  Depth = 0,
Instruction CxtI = nullptr 
) const
inline

Definition at line 474 of file InstCombineInternal.h.

References llvm::ComputeNumSignBits(), and llvm::DL.

Referenced by ProcessUGT_ADDCST_ADD().

OverflowResult llvm::InstCombiner::computeOverflowForUnsignedAdd ( Value LHS,
Value RHS,
const Instruction CxtI 
)
inline

Definition at line 487 of file InstCombineInternal.h.

References llvm::computeOverflowForUnsignedAdd(), and llvm::DL.

OverflowResult llvm::InstCombiner::computeOverflowForUnsignedMul ( Value LHS,
Value RHS,
const Instruction CxtI 
)
inline

Definition at line 483 of file InstCombineInternal.h.

References llvm::computeOverflowForUnsignedMul(), and llvm::DL.

void llvm::InstCombiner::ComputeSignBit ( Value V,
bool KnownZero,
bool KnownOne,
unsigned  Depth = 0,
Instruction CxtI = nullptr 
) const
inline

Definition at line 478 of file InstCombineInternal.h.

References llvm::ComputeSignBit(), and llvm::DL.

Referenced by canReplaceGEPIdxWithZero().

Instruction* llvm::InstCombiner::CreateOverflowTuple ( IntrinsicInst II,
Value Result,
Constant Overflow 
)
inline

Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value.

Definition at line 434 of file InstCombineInternal.h.

References llvm::InsertValueInst::Create(), llvm::ConstantStruct::get(), llvm::UndefValue::get(), llvm::Value::getType(), llvm::AArch64DB::ST, and llvm::Struct.

bool InstCombiner::dominatesAllUses ( const Instruction DI,
const Instruction UI,
const BasicBlock DB 
) const

Check that one use is in the same block as the definition and all other uses are in blocks dominated by a given block.

Parameters
DIDefinition
UIUse
DBBlock that must dominate all uses of DI outside the parent block
Returns
true when UI is the only use of DI in the parent block and all other uses of DI are in blocks dominated by DB.

Definition at line 2525 of file InstCombineCompares.cpp.

References llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), and llvm::Value::users().

Instruction* llvm::InstCombiner::EraseInstFromFunction ( Instruction I)
inline

Combiner aware instruction erasure.

When dealing with an instruction that has side effects or produces a void value, we can't rely on DCE to delete the instruction. Instead, visit methods should return the value returned by this function.

Definition at line 447 of file InstCombineInternal.h.

References llvm::dbgs(), DEBUG, llvm::Instruction::eraseFromParent(), llvm::User::getNumOperands(), llvm::User::op_begin(), llvm::User::op_end(), and llvm::Value::use_empty().

Referenced by combineLoadToOperationType(), visitAllocaInst(), and visitStoreInst().

Value * InstCombiner::FoldAndOfFCmps ( FCmpInst LHS,
FCmpInst RHS 
)

FoldAndOfFCmps - Optimize (fcmp)&(fcmp).

NOTE: Unlike the rest of instcombine, this returns a Value which should already be inserted into the function.

Definition at line 1129 of file InstCombineAndOrXor.cpp.

References llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::ConstantInt::get(), getFCmpCode(), getFCmpValue(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), llvm::CmpInst::makeCmpResultType(), and std::swap().

Value * InstCombiner::FoldAndOfICmps ( ICmpInst LHS,
ICmpInst RHS 
)
Instruction * InstCombiner::FoldCmpLoadFromIndexedGlobal ( GetElementPtrInst GEP,
GlobalVariable GV,
CmpInst ICI,
ConstantInt AndCst = nullptr 
)

FoldCmpLoadFromIndexedGlobal - Called we see this pattern: cmp pred (load (gep GV, ...)), cmpcst where GV is a global variable with a constant initializer.

Try to simplify this into some simple computation that does not need the load. For example we can optimize "icmp eq (load (gep "foo", 0, i)), 0" into "icmp eq i, 3".

If AndCst is non-null, then the loaded value is masked with that constant before doing the comparison. This handles cases like "A[i]&4 == 0".

TrueRangeEnd/FalseRangeEnd - In conjunction with First*Element, these define a state machine that triggers for ranges of values that the index is true or false for. This triggers on things like "abbbbc"[i] == 'b'. This is -2 when undefined, -3 when overdefined, and otherwise the last index in the range (inclusive). We use -2 for undefined here because we use relative comparisons and don't want 0-1 to match -1.

Definition at line 230 of file InstCombineCompares.cpp.

References llvm::ConstantFoldCompareInstOperands(), llvm::DL, llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::ConstantInt::get(), llvm::Constant::getAggregateElement(), llvm::ConstantExpr::getAnd(), llvm::Type::getArrayElementType(), llvm::Type::getArrayNumElements(), llvm::Value::getContext(), llvm::ConstantExpr::getExtractValue(), llvm::GlobalVariable::getInitializer(), llvm::Type::getIntegerBitWidth(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Type::getPrimitiveSizeInBits(), llvm::Intrinsic::getType(), llvm::Value::getType(), llvm::GetElementPtrInst::getType(), llvm::ConstantInt::getZExtValue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::GetElementPtrInst::isInBounds(), isZero(), and llvm::SmallVectorTemplateBase< T, isPodLike >::push_back().

Instruction * InstCombiner::FoldFCmp_IntToFP_Cst ( FCmpInst I,
Instruction LHSI,
Constant RHSC 
)

FoldFCmp_IntToFP_Cst - Fold fcmp ([us]itofp x, cst) if possible.

Definition at line 3687 of file InstCombineCompares.cpp.

References llvm::APFloat::cmpEqual, llvm::APFloat::cmpGreaterThan, llvm::APFloat::cmpLessThan, llvm::APFloat::compare(), llvm::APFloat::convertFromAPInt(), llvm::APFloat::convertToInteger(), llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::IntegerType::getBitWidth(), llvm::Type::getFPMantissaWidth(), llvm::ConstantExpr::getFPToSI(), llvm::ConstantExpr::getFPToUI(), llvm::APInt::getMaxValue(), llvm::APInt::getMinValue(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Type::getScalarSizeInBits(), llvm::APFloat::getSemantics(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), llvm::ConstantExpr::getSIToFP(), llvm::Value::getType(), llvm::ConstantExpr::getUIToFP(), 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::FCmpInst::isEquality(), llvm::APFloat::isNaN(), llvm::APFloat::isNegative(), llvm::APFloat::isPosZero(), llvm::APFloat::isZero(), llvm_unreachable, P, llvm::APFloat::rmNearestTiesToEven, and llvm::APFloat::roundToIntegral().

Value * InstCombiner::foldFMulConst ( Instruction FMulOrDiv,
Constant C,
Instruction InsertBefore 
)

foldFMulConst() is a helper routine of InstCombiner::visitFMul().

The input FMulOrDiv is a FMul/FDiv with one and only one operand being a constant (i.e. isFMulOrFDivWithConstant(FMulOrDiv) == true). This function is to simplify "FMulOrDiv * C" and returns the resulting expression. Note that this function could return NULL in case the constants cannot be folded into a normal floating-point.

Definition at line 479 of file InstCombineMulDivRem.cpp.

References llvm::dyn_cast(), F(), llvm::ConstantExpr::getFDiv(), llvm::ConstantExpr::getFMul(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::hasOneUse(), isFMulOrFDivWithConstant(), and isNormalFp().

Instruction * InstCombiner::FoldGEPICmp ( GEPOperator GEPLHS,
Value RHS,
ICmpInst::Predicate  Cond,
Instruction I 
)
Instruction * InstCombiner::FoldICmpAddOpCst ( Instruction ICI,
Value X,
ConstantInt CI,
ICmpInst::Predicate  Pred 
)
Instruction * InstCombiner::FoldICmpCstShlCst ( ICmpInst I,
Value Op,
Value A,
ConstantInt CI1,
ConstantInt CI2 
)
Instruction * InstCombiner::FoldICmpCstShrCst ( ICmpInst I,
Value Op,
Value A,
ConstantInt CI1,
ConstantInt CI2 
)
Instruction * InstCombiner::FoldICmpDivCst ( ICmpInst ICI,
BinaryOperator DivI,
ConstantInt DivRHS 
)
Instruction * InstCombiner::FoldICmpShrCst ( ICmpInst ICI,
BinaryOperator DivI,
ConstantInt DivRHS 
)
Instruction * InstCombiner::FoldItoFPtoI ( Instruction FI)
Value * InstCombiner::FoldOrOfFCmps ( FCmpInst LHS,
FCmpInst RHS 
)

FoldOrOfFCmps - Optimize (fcmp)|(fcmp).

NOTE: Unlike the rest of instcombine, this returns a Value which should already be inserted into the function.

Definition at line 2026 of file InstCombineAndOrXor.cpp.

References llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UNO, llvm::ConstantInt::get(), getFCmpCode(), getFCmpValue(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), llvm::CmpInst::makeCmpResultType(), and std::swap().

Value * InstCombiner::FoldOrOfICmps ( ICmpInst LHS,
ICmpInst RHS,
Instruction CxtI 
)
Instruction * InstCombiner::FoldOrWithConstants ( BinaryOperator I,
Value Op,
Value A,
Value B,
Value C 
)

FoldOrWithConstants - This helper function folds:

((A | B) & C1) | (B & C2)

into:

(A & C1) | B

when the XOR of the two constants is "all ones" (-1).

Definition at line 2092 of file InstCombineAndOrXor.cpp.

References llvm::dyn_cast(), llvm::ConstantInt::getValue(), llvm::APInt::isAllOnesValue(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::APIntOps::Xor().

Instruction * InstCombiner::FoldSelectIntoOp ( SelectInst SI,
Value TrueVal,
Value FalseVal 
)
Instruction * InstCombiner::FoldSelectOpOp ( SelectInst SI,
Instruction TI,
Instruction FI 
)
Instruction * InstCombiner::FoldShiftByConstant ( Value Op0,
Constant Op1,
BinaryOperator I 
)
Instruction* llvm::InstCombiner::FoldSPFofSPF ( Instruction Inner,
SelectPatternFlavor  SPF1,
Value A,
Value B,
Instruction Outer,
SelectPatternFlavor  SPF2,
Value C 
)
Instruction * InstCombiner::FoldXorWithConstants ( BinaryOperator I,
Value Op,
Value A,
Value B,
Value C 
)

This helper function folds:

((A | B) & C1) ^ (B & C2)

into:

(A & C1) ^ B

when the XOR of the two constants is "all ones" (-1).

Definition at line 2121 of file InstCombineAndOrXor.cpp.

References llvm::dyn_cast(), llvm::ConstantInt::getValue(), llvm::APInt::isAllOnesValue(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::APIntOps::Xor().

AssumptionCache* llvm::InstCombiner::getAssumptionCache ( ) const
inline

Definition at line 209 of file InstCombineInternal.h.

Referenced by simplifyValueKnownNonZero().

const DataLayout& llvm::InstCombiner::getDataLayout ( ) const
inline
DominatorTree* llvm::InstCombiner::getDominatorTree ( ) const
inline

Definition at line 213 of file InstCombineInternal.h.

Referenced by simplifyValueKnownNonZero().

LoopInfo* llvm::InstCombiner::getLoopInfo ( ) const
inline

Definition at line 215 of file InstCombineInternal.h.

TargetLibraryInfo* llvm::InstCombiner::getTargetLibraryInfo ( ) const
inline

Definition at line 217 of file InstCombineInternal.h.

Referenced by GetShiftedValue().

Instruction* llvm::InstCombiner::InsertNewInstBefore ( Instruction New,
Instruction Old 
)
inline

Inserts an instruction New before instruction Old.

Also adds the new instruction to the worklist and returns New so that it is suitable for use as the return from the visitation patterns.

Definition at line 392 of file InstCombineInternal.h.

References llvm::BasicBlock::getInstList(), llvm::Instruction::getParent(), and llvm::iplist< NodeTy, Traits >::insert().

Referenced by simplifyAllocaArraySize().

Instruction* llvm::InstCombiner::InsertNewInstWith ( Instruction New,
Instruction Old 
)
inline

Same as InsertNewInstBefore, but also sets the debug loc.

Definition at line 402 of file InstCombineInternal.h.

References llvm::Instruction::getDebugLoc(), and llvm::Instruction::setDebugLoc().

bool llvm::InstCombiner::MaskedValueIsZero ( Value V,
const APInt Mask,
unsigned  Depth = 0,
Instruction CxtI = nullptr 
) const
inline

Definition at line 470 of file InstCombineInternal.h.

References llvm::DL, and llvm::MaskedValueIsZero().

Value * InstCombiner::OptimizePointerDifference ( Value LHS,
Value RHS,
Type Ty 
)

Optimize pointer differences into the same array into a size.

Consider: &A[10] - &A[0]: we should compile this to "10". LHS/RHS are the pointer operands to the ptrtoint instructions for the LHS/RHS of the subtract.

Definition at line 1429 of file InstCombineAddSub.cpp.

References llvm::EmitGEPOffset().

bool InstCombiner::replacedSelectWithOperand ( SelectInst SI,
const ICmpInst Icmp,
const unsigned  SIOpd 
)

True when a select result is replaced by one of its operands in select-icmp sequence.

This will eventually result in the elimination of the select.

Parameters
SISelect instruction
IcmpCompare instruction
SIOpdOperand that replaces the select

Notes:

  • The replacement is global and requires dominator information
  • The caller is responsible for the actual replacement

Example:

entry: %4 = select i1 %3, C* %0, C* null %5 = icmp eq C* %4, null br i1 %5, label %9, label %7 ... ; <label>:7 ; preds = entry %8 = getelementptr inbounds C* %4, i64 0, i32 0 ...

can be transformed to

%5 = icmp eq C* %0, null %6 = select i1 %3, i1 %5, i1 true br i1 %6, label %9, label %7 ... ; <label>:7 ; preds = entry %8 = getelementptr inbounds C* %0, i64 0, i32 0 // replace by %0!

Similar when the first operand of the select is a constant or/and the compare is for not equal rather than equal.

NOTE: The function is only called when the select and compare constants are equal, the optimization can work only for EQ predicates. This is not a major restriction since a NE compare should be 'normalized' to an equal compare, which usually happens in the combiner and test case select-cmp-br.ll checks for it.

Definition at line 2607 of file InstCombineCompares.cpp.

References llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::CmpInst::getPredicate(), llvm::TerminatorInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::getUniquePredecessor(), llvm::CmpInst::ICMP_EQ, isChainSelectCmpBranch(), and llvm::Value::replaceUsesOutsideBlock().

Instruction* llvm::InstCombiner::ReplaceInstUsesWith ( Instruction I,
Value V 
)
inline

A combiner-aware RAUW-like routine.

This method is to be used when an instruction is found to be dead, replacable with another preexisting expression. Here we add all uses of I to the worklist, replace all uses of I with the new value, then return I, so that the inst combiner will know that I was modified.

Definition at line 413 of file InstCombineInternal.h.

References llvm::dbgs(), DEBUG, llvm::UndefValue::get(), llvm::Value::getType(), I, llvm::Value::replaceAllUsesWith(), and llvm::Value::use_empty().

Referenced by ProcessUGT_ADDCST_ADD(), ProcessUMulZExtIdiom(), simplifyAllocaArraySize(), SliceUpIllegalIntegerPHI(), unpackLoadToAggregate(), visitAllocaInst(), visitLoadInst(), and visitPHINode().

bool InstCombiner::run ( )
bool InstCombiner::SimplifyDivRemOfSelect ( BinaryOperator I)

SimplifyDivRemOfSelect - Try to fold a divide or remainder of a select instruction.

Definition at line 710 of file InstCombineMulDivRem.cpp.

References llvm::BasicBlock::begin(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::hasOneUse(), I, llvm::User::setOperand(), SI, llvm::AArch64DB::ST, and llvm::Value::use_empty().

Value * InstCombiner::simplifyRangeCheck ( ICmpInst Cmp0,
ICmpInst Cmp1,
bool  Inverted 
)

Try to fold a signed range checked with lower bound 0 to an unsigned icmp.

Example: (icmp sge x, 0) & (icmp slt x, n) –> icmp ult x, n If Inverted is true then the check is for the inverted range, e.g. (icmp slt x, 0) | (icmp sgt x, n) –> icmp ugt x, n

Definition at line 830 of file InstCombineAndOrXor.cpp.

References llvm::ComputeSignBit(), llvm::dyn_cast(), llvm::CmpInst::getInversePredicate(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::getSwappedPredicate(), llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ConstantInt::isMinusOne(), and llvm::ConstantInt::isZero().

Instruction * InstCombiner::SliceUpIllegalIntegerPHI ( PHINode FirstPhi)

This is an integer PHI and we know that it has an illegal type: see if it is only used by trunc or trunc(lshr) operations.

If so, we split the PHI into the various pieces being extracted. This sort of thing is introduced when SROA promotes an aggregate to large integer values.

TODO: The user of the trunc may be an bitcast to float/double/vector or an inttoptr. We should produce new PHIs in the right type.

Definition at line 614 of file InstCombinePHI.cpp.

References llvm::PHINode::addIncoming(), llvm::array_pod_sort(), llvm::SmallVectorTemplateCommon< T >::begin(), Builder, llvm::SmallPtrSetImpl< PtrType >::count(), llvm::PHINode::Create(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateLShr(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateTrunc(), llvm::dbgs(), DEBUG, llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), ReplaceInstUsesWith(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallVectorTemplateCommon< T >::size(), llvm::RegState::Undef, llvm::Instruction::user_back(), and llvm::Value::users().

Referenced by visitPHINode().

Instruction * InstCombiner::visitAdd ( BinaryOperator I)

Definition at line 1050 of file InstCombineAddSub.cpp.

References llvm::ARM_PROC::A, llvm::AddOne(), checkForNegativeOperand(), llvm::computeKnownBits(), llvm::computeOverflowForUnsignedAdd(), llvm::SelectInst::Create(), CreateAdd(), llvm::BinaryOperator::CreateNeg(), llvm::DL, llvm::dyn_cast(), llvm::ConstantInt::get(), llvm::ConstantExpr::getAdd(), llvm::IntegerType::getBitWidth(), llvm::SelectInst::getCondition(), llvm::SelectInst::getFalseValue(), llvm::APInt::getHighBitsSet(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::ConstantExpr::getSExt(), llvm::SelectInst::getTrueValue(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::ConstantExpr::getXor(), llvm::BinaryOperator::hasNoSignedWrap(), llvm::BinaryOperator::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::haveNoCommonBitsSet(), I, llvm::Type::isIntegerTy(), llvm::APInt::isPowerOf2(), llvm::APInt::isSignBit(), IT(), llvm::APInt::logBase2(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::MaskedValueIsZero(), llvm::PatternMatch::match(), N, llvm::NeverOverflows, llvm::AArch64CC::NV, llvm::BinaryOperator::setHasNoSignedWrap(), llvm::BinaryOperator::setHasNoUnsignedWrap(), SI, llvm::SimplifyAddInst(), llvm::SubOne(), and X.

Instruction * InstCombiner::visitAddrSpaceCast ( AddrSpaceCastInst CI)
Instruction * InstCombiner::visitAllocaInst ( AllocaInst AI)
Instruction * InstCombiner::visitAllocSite ( Instruction FI)
Instruction * InstCombiner::visitAnd ( BinaryOperator I)
Instruction * InstCombiner::visitAShr ( BinaryOperator I)
Instruction * InstCombiner::visitBitCast ( BitCastInst CI)
Instruction * InstCombiner::visitBranchInst ( BranchInst BI)
Instruction * InstCombiner::visitCallInst ( CallInst CI)

visitCallInst - CallInst simplification.

This mostly only handles folding of intrinsic instructions. For normal calls, it allows visitCallSite to do the heavy lifting.

Definition at line 326 of file InstCombineCalls.cpp.

References llvm::ARM_PROC::A, llvm::CallInst::arg_operands(), llvm::computeKnownBits(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::CastInst::CreateIntegerCast(), llvm::APFloat::divide(), llvm::DL, llvm::Function::doesNotThrow(), llvm::CallInst::doesNotThrow(), llvm::dyn_cast(), F(), llvm::ConstantInt::get(), llvm::ConstantFP::get(), llvm::ConstantAggregateZero::get(), llvm::VectorType::get(), llvm::ConstantVector::get(), llvm::ConstantPointerNull::get(), llvm::ConstantDataVector::get(), llvm::MDNode::get(), llvm::UndefValue::get(), llvm::Constant::getAggregateElement(), llvm::CallInst::getArgOperand(), llvm::APInt::getBitsSet(), llvm::IntegerType::getBitWidth(), llvm::CallInst::getCalledValue(), llvm::Value::getContext(), llvm::Intrinsic::getDeclaration(), llvm::GCRelocateOperands::getDerivedPtr(), llvm::APInt::getHighBitsSet(), llvm::Type::getInt32Ty(), llvm::ConstantExpr::getIntegerCast(), llvm::IntrinsicInst::getIntrinsicID(), llvm::getKnownAlignment(), llvm::APInt::getLowBitsSet(), llvm::ConstantExpr::getMul(), llvm::getObjectSize(), llvm::getOrEnforceKnownAlignment(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Type::getPrimitiveSizeInBits(), llvm::APFloat::getSemantics(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::PointerType::getUnqual(), llvm::ConstantInt::getZExtValue(), I, llvm::CmpInst::ICMP_NE, llvm::IntrinsicIDToOverflowCheckFlavor(), llvm::APInt::isAllOnesValue(), llvm::isDereferenceablePointer(), llvm::isFreeCall(), llvm::isKnownNonNull(), llvm::Type::isPointerTy(), llvm::isValidAssumeForContext(), IT(), llvm::SPII::Load, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_BSwap(), llvm::PatternMatch::m_FMax(), llvm::PatternMatch::m_FMin(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::makeArrayRef(), llvm::PatternMatch::match(), llvm::maxnum(), llvm::LLVMContext::MD_nonnull, llvm::minnum(), llvm::None, llvm::Attribute::NonNull, llvm::OCF_INVALID, Operands, llvm::APFloat::opOK, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::AttributeSet::ReturnIndex, llvm::APFloat::rmNearestTiesToEven, llvm::CallInst::setArgOperand(), llvm::CallInst::setCalledFunction(), llvm::CallInst::setDoesNotThrow(), llvm::Instruction::setMetadata(), llvm::SimplifyCall(), SimplifyX86insertps(), SimplifyX86vperm2(), llvm::Sched::Source, llvm::SS, std::swap(), llvm::RegState::Undef, llvm::NVPTX::PTXLdStInstCode::V2, X, and Y.

Instruction * InstCombiner::visitExtractElementInst ( ExtractElementInst EI)
Instruction * InstCombiner::visitExtractValueInst ( ExtractValueInst EV)
Instruction * InstCombiner::visitFAdd ( BinaryOperator I)
Instruction * InstCombiner::visitFCmpInst ( FCmpInst I)

Orders the operands of the compare so that they are listed from most complex to least complex. This puts constants before unary operators, before binary operators.

Definition at line 3917 of file InstCombineCompares.cpp.

References llvm::Call, llvm::APFloat::clearSign(), llvm::APFloat::cmpLessThan, llvm::APFloat::compare(), llvm::APFloat::convert(), llvm::DL, llvm::dyn_cast(), F(), llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, GEP, llvm::ConstantFP::get(), llvm::CallInst::getArgOperand(), llvm::CallInst::getCalledFunction(), llvm::getComplexity(), llvm::Instruction::getFastMathFlags(), llvm::ConstantExpr::getFNeg(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::CmpInst::getPredicate(), llvm::APFloat::getSmallestNormalized(), llvm::CastInst::getSrcTy(), llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::APFloat::IEEEdouble, llvm::APFloat::IEEEhalf, llvm::APFloat::IEEEquad, llvm::APFloat::IEEEsingle, llvm::Type::isDoubleTy(), llvm::Type::isFloatTy(), llvm::Type::isFP128Ty(), llvm::Type::isHalfTy(), llvm::Type::isPPC_FP128Ty(), isVolatile(), llvm::Type::isX86_FP80Ty(), llvm::APFloat::isZero(), llvm_unreachable, llvm::SPII::Load, llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::AArch64CC::NV, llvm::TargetOpcode::PHI, llvm::APFloat::PPCDoubleDouble, llvm::APFloat::rmNearestTiesToEven, llvm::User::setOperand(), llvm::CmpInst::setPredicate(), SI, llvm::SimplifyFCmpInst(), llvm::FCmpInst::swapOperands(), llvm::Value::user_begin(), X, llvm::APFloat::x87DoubleExtended, and Y.

Instruction * InstCombiner::visitFDiv ( BinaryOperator I)
Instruction * InstCombiner::visitFMul ( BinaryOperator I)
Instruction * InstCombiner::visitFPExt ( CastInst CI)

Definition at line 1343 of file InstCombineCasts.cpp.

Instruction * InstCombiner::visitFPToSI ( FPToSIInst FI)

Definition at line 1402 of file InstCombineCasts.cpp.

References llvm::dyn_cast(), llvm::User::getOperand(), and I.

Instruction * InstCombiner::visitFPToUI ( FPToUIInst FI)

Definition at line 1391 of file InstCombineCasts.cpp.

References llvm::dyn_cast(), llvm::User::getOperand(), and I.

Instruction * InstCombiner::visitFPTrunc ( FPTruncInst CI)
Instruction * InstCombiner::visitFree ( CallInst FI)
Instruction * InstCombiner::visitFRem ( BinaryOperator I)
Instruction * InstCombiner::visitFSub ( BinaryOperator I)
Instruction * InstCombiner::visitGetElementPtrInst ( GetElementPtrInst GEP)

See if we can simplify: X = bitcast A* to B* Y = gep X, <...constant indices...> into a gep of the original struct. This is important for SROA and alias analysis of unions. If "A" is also a bitcast, wait for A/X to be merged.

Definition at line 1315 of file InstructionCombining.cpp.

References llvm::GetElementPtrInst::accumulateConstantOffset(), llvm::PHINode::addIncoming(), llvm::SmallVectorImpl< T >::append(), llvm::CallingConv::C, llvm::Instruction::clone(), llvm::CastInst::Create(), llvm::GetElementPtrInst::Create(), llvm::GetElementPtrInst::CreateInBounds(), llvm::CastInst::CreatePointerBitCastOrAddrSpaceCast(), llvm::DI, llvm::DL, llvm::dyn_cast(), llvm::SmallVectorBase::empty(), F(), GEP, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::PointerType::getAddressSpace(), llvm::GetElementPtrInst::getAddressSpace(), llvm::Type::getArrayElementType(), llvm::SequentialType::getElementType(), llvm::BasicBlock::getFirstInsertionPt(), llvm::PHINode::getIncomingBlock(), llvm::BasicBlock::getInstList(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::GetElementPtrInst::getNumIndices(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Type::getPointerAddressSpace(), llvm::GetElementPtrInst::getPointerAddressSpace(), llvm::Type::getPointerElementType(), llvm::GetElementPtrInst::getPointerOperandType(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::APInt::getSExtValue(), llvm::Value::getType(), llvm::GetElementPtrInst::getType(), I, llvm::GetElementPtrInst::idx_begin(), llvm::GetElementPtrInst::idx_end(), llvm::iplist< NodeTy, Traits >::insert(), llvm::isAllocationFn(), llvm::Type::isArrayTy(), llvm::GetElementPtrInst::isInBounds(), llvm::Type::isSized(), llvm::Type::isStructTy(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::User::op_begin(), llvm::User::op_end(), llvm::User::operands(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::User::setOperand(), llvm::GetElementPtrInst::setSourceElementType(), shouldMergeGEPs(), llvm::SimplifyGEPInst(), llvm::Value::stripPointerCasts(), llvm::Value::takeName(), and Y.

Instruction * InstCombiner::visitICmpInst ( ICmpInst I)

Orders the operands of the compare so that they are listed from most complex to least complex. This puts constants before unary operators, before binary operators.

Definition at line 2631 of file InstCombineCompares.cpp.

References llvm::ARM_PROC::A, llvm::APInt::abs(), llvm::APIntOps::And(), ComputeSignedMinMaxValuesFromKnownBits(), ComputeUnsignedMinMaxValuesFromKnownBits(), llvm::APInt::countTrailingZeros(), llvm::CmpInst::Create(), llvm::SelectInst::Create(), llvm::ExtractValueInst::Create(), llvm::BinaryOperator::CreateNot(), DemandedBitsLHSMask(), llvm::DL, llvm::dyn_cast(), GEP, llvm::ConstantInt::get(), llvm::Constant::getAllOnesValue(), llvm::APInt::getAllOnesValue(), llvm::ConstantExpr::getBitCast(), getBitWidth(), llvm::ConstantInt::getBitWidth(), llvm::APInt::getBitWidth(), llvm::getComplexity(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), llvm::ConstantExpr::getICmp(), llvm::CmpInst::getInversePredicate(), llvm::ConstantInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::Value::getName(), llvm::ConstantExpr::getNeg(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::User::getOperandUse(), llvm::Instruction::getParent(), llvm::CmpInst::getPredicate(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::ICmpInst::getSignedPredicate(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::ConstantInt::getType(), llvm::Value::getType(), llvm::ICmpInst::getUnsignedPredicate(), llvm::ConstantInt::getValue(), llvm::BinaryOperator::hasNoSignedWrap(), llvm::BinaryOperator::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), I, 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::ICmpInst::isEquality(), llvm::BinaryOperator::isExact(), llvm::Type::isIntegerTy(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownToBeAPowerOfTwo(), llvm::APInt::isNegative(), llvm::Type::isPointerTy(), llvm::APInt::isPowerOf2(), isSignBitCheck(), llvm::CmpInst::isSigned(), llvm::CmpInst::isUnsigned(), isVolatile(), llvm::ConstantInt::isZero(), llvm_unreachable, llvm::SPII::Load, llvm::APInt::logBase2(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_UAddWithOverflow(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), NC, llvm::APIntOps::Not(), llvm::AArch64CC::NV, llvm::OCF_UNSIGNED_ADD, llvm::TargetOpcode::PHI, ProcessUGT_ADDCST_ADD(), ProcessUMulZExtIdiom(), llvm::MCID::Select, llvm::User::setOperand(), SI, llvm::SimplifyICmpInst(), llvm::APInt::sle(), llvm::APInt::slt(), std::swap(), swapMayExposeCSEOpportunities(), llvm::ICmpInst::swapOperands(), llvm::APInt::uge(), llvm::APInt::ule(), llvm::APInt::ult(), llvm::Value::user_begin(), X, llvm::APIntOps::Xor(), Y, and llvm::APInt::zext().

Instruction * InstCombiner::visitICmpInstWithCastAndCast ( ICmpInst ICI)
Instruction * InstCombiner::visitICmpInstWithInstAndIntCst ( ICmpInst ICI,
Instruction LHS,
ConstantInt RHS 
)

visitICmpInstWithInstAndIntCst - Handle "icmp (instr, intcst)".

Definition at line 1141 of file InstCombineCompares.cpp.

References llvm::AddOne(), llvm::APIntOps::And(), llvm::APInt::byteSwap(), llvm::computeKnownBits(), llvm::APInt::countTrailingZeros(), llvm::dyn_cast(), GEP, llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::ConstantExpr::get(), llvm::APInt::getActiveBits(), llvm::ConstantExpr::getAnd(), llvm::ConstantExpr::getAShr(), llvm::IntegerType::getBitWidth(), getBitWidth(), llvm::ConstantInt::getBitWidth(), llvm::APInt::getBitWidth(), llvm::Value::getContext(), llvm::APInt::getHighBitsSet(), llvm::ConstantInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::ConstantRange::getLower(), llvm::ConstantExpr::getLShr(), llvm::Value::getName(), llvm::ConstantExpr::getNeg(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::ConstantExpr::getNUWShl(), llvm::APInt::getOneBitSet(), llvm::Instruction::getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ConstantExpr::getOr(), llvm::CmpInst::getPredicate(), llvm::Type::getPrimitiveSizeInBits(), llvm::ConstantExpr::getShl(), llvm::ICmpInst::getSignedPredicate(), llvm::ConstantExpr::getSub(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantExpr::getTrunc(), llvm::ConstantInt::getType(), llvm::Value::getType(), llvm::ICmpInst::getUnsignedPredicate(), llvm::ConstantRange::getUpper(), llvm::ConstantInt::getValue(), llvm::ConstantExpr::getXor(), llvm::ConstantExpr::getZExt(), llvm::ConstantInt::getZExtValue(), llvm::Value::hasOneUse(), 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::APInt::isAllOnesValue(), llvm::Instruction::isArithmeticShift(), llvm::ICmpInst::isEquality(), llvm::BinaryOperator::isExact(), isHighOnes(), llvm::APInt::isMinValue(), llvm::ConstantInt::isNegative(), llvm::APInt::isNonNegative(), llvm::Constant::isNullValue(), llvm::APInt::isPowerOf2(), llvm::Instruction::isShift(), llvm::APInt::isSignBit(), isSignBitCheck(), llvm::CmpInst::isSigned(), isSignTest(), llvm::CmpInst::isUnsigned(), llvm::ConstantInt::isZero(), llvm::APInt::logBase2(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::ICmpInst::makeConstantRange(), llvm::PatternMatch::match(), One, llvm::APIntOps::Or(), P, pred, llvm::User::setOperand(), llvm::APInt::sgt(), llvm::SubOne(), llvm::Value::takeName(), llvm::ConstantInt::uge(), X, llvm::APIntOps::Xor(), Y, and llvm::APInt::zext().

Instruction * InstCombiner::visitInsertElementInst ( InsertElementInst IE)
Instruction * InstCombiner::visitInsertValueInst ( InsertValueInst I)

Try to find redundant insertvalue instructions, like the following ones: %0 = insertvalue { i8, i32 } undef, i8 x, 0 %1 = insertvalue { i8, i32 } %0, i8 y, 0 Here the second instruction inserts values at the same indices, as the first one, making the first one redundant.

It should be transformed to: %0 = insertvalue { i8, i32 } undef, i8 y, 0

Definition at line 452 of file InstCombineVectorOps.cpp.

References llvm::dyn_cast(), llvm::InsertValueInst::getIndices(), llvm::User::getOperand(), llvm::Value::hasOneUse(), I, and llvm::Value::user_back().

Instruction* llvm::InstCombiner::visitInstruction ( Instruction I)
inline

Definition at line 331 of file InstCombineInternal.h.

Instruction * InstCombiner::visitIntToPtr ( IntToPtrInst CI)
Instruction * InstCombiner::visitInvokeInst ( InvokeInst II)

Definition at line 1259 of file InstCombineCalls.cpp.

Instruction * InstCombiner::visitLandingPadInst ( LandingPadInst LI)
Instruction * InstCombiner::visitLoadInst ( LoadInst LI)
Instruction * InstCombiner::visitLShr ( BinaryOperator I)
Instruction * InstCombiner::visitMul ( BinaryOperator I)
Instruction * InstCombiner::visitOr ( BinaryOperator I)
Instruction * InstCombiner::visitPHINode ( PHINode PN)
Instruction * InstCombiner::visitPtrToInt ( PtrToIntInst CI)
Instruction * InstCombiner::visitReturnInst ( ReturnInst RI)
Instruction * InstCombiner::visitSDiv ( BinaryOperator I)
Instruction* llvm::InstCombiner::visitSelectInst ( SelectInst SI)
Instruction* llvm::InstCombiner::visitSelectInstWithICmp ( SelectInst SI,
ICmpInst ICI 
)
Instruction * InstCombiner::visitSExt ( SExtInst CI)
Instruction * InstCombiner::visitShl ( BinaryOperator I)
Instruction * InstCombiner::visitShuffleVectorInst ( ShuffleVectorInst SVI)
Instruction * InstCombiner::visitSIToFP ( CastInst CI)

Definition at line 1417 of file InstCombineCasts.cpp.

Instruction * InstCombiner::visitSRem ( BinaryOperator I)
Instruction * InstCombiner::visitStoreInst ( StoreInst SI)
Instruction * InstCombiner::visitSub ( BinaryOperator I)

Definition at line 1493 of file InstCombineAddSub.cpp.

References llvm::ARM_PROC::A, llvm::AddOne(), llvm::computeKnownBits(), llvm::SelectInst::Create(), CreateAdd(), llvm::BinaryOperator::CreateNeg(), llvm::BinaryOperator::CreateNot(), llvm::CastInst::CreateSExtOrBitCast(), llvm::CastInst::CreateZExtOrBitCast(), llvm::DL, llvm::ConstantExpr::getNeg(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::BinaryOperator::hasNoSignedWrap(), llvm::BinaryOperator::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::tgtok::IntVal, llvm::Type::isIntegerTy(), llvm::Constant::isNotMinSignedValue(), llvm::Constant::isOneValue(), llvm::APFloat::isZero(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::BinaryOperator::setHasNoSignedWrap(), llvm::BinaryOperator::setHasNoUnsignedWrap(), SI, llvm::SimplifySubInst(), X, and Y.

Instruction * InstCombiner::visitSwitchInst ( SwitchInst SI)
Instruction * InstCombiner::visitTrunc ( TruncInst CI)
Instruction * InstCombiner::visitUDiv ( BinaryOperator I)
Instruction * InstCombiner::visitUIToFP ( CastInst CI)

Definition at line 1413 of file InstCombineCasts.cpp.

Instruction * InstCombiner::visitURem ( BinaryOperator I)
Instruction * InstCombiner::visitXor ( BinaryOperator I)
Instruction * InstCombiner::visitZExt ( ZExtInst CI)

Member Data Documentation

BuilderTy* llvm::InstCombiner::Builder
InstCombineWorklist& llvm::InstCombiner::Worklist

A worklist of the instructions that need to be simplified.

Definition at line 170 of file InstCombineInternal.h.

Referenced by GetShiftedValue(), ProcessUMulZExtIdiom(), visitLoadInst(), and visitStoreInst().


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