LLVM 19.0.0git
Public Member Functions | List of all members
llvm::InstCombinerImpl Class Referencefinal

#include "Transforms/InstCombine/InstCombineInternal.h"

Inheritance diagram for llvm::InstCombinerImpl:
Inheritance graph
[legend]

Public Member Functions

 InstCombinerImpl (InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI, ProfileSummaryInfo *PSI, const DataLayout &DL, LoopInfo *LI)
 
virtual ~InstCombinerImpl ()=default
 
bool prepareWorklist (Function &F, ReversePostOrderTraversal< BasicBlock * > &RPOT)
 Perform early cleanup and prepare the InstCombine worklist.
 
bool run ()
 Run the combiner over the entire worklist until it is empty.
 
InstructionvisitFNeg (UnaryOperator &I)
 
InstructionvisitAdd (BinaryOperator &I)
 
InstructionvisitFAdd (BinaryOperator &I)
 
ValueOptimizePointerDifference (Value *LHS, Value *RHS, Type *Ty, bool isNUW)
 Optimize pointer differences into the same array into a size.
 
InstructionvisitSub (BinaryOperator &I)
 
InstructionvisitFSub (BinaryOperator &I)
 
InstructionvisitMul (BinaryOperator &I)
 
InstructionfoldPowiReassoc (BinaryOperator &I)
 
InstructionfoldFMulReassoc (BinaryOperator &I)
 
InstructionvisitFMul (BinaryOperator &I)
 
InstructionvisitURem (BinaryOperator &I)
 
InstructionvisitSRem (BinaryOperator &I)
 
InstructionvisitFRem (BinaryOperator &I)
 
bool simplifyDivRemOfSelectWithZeroOp (BinaryOperator &I)
 Fold a divide or remainder with a select instruction divisor when one of the select operands is zero.
 
InstructioncommonIRemTransforms (BinaryOperator &I)
 This function implements the transforms common to both integer remainder instructions (urem and srem).
 
InstructioncommonIDivTransforms (BinaryOperator &I)
 This function implements the transforms common to both integer division instructions (udiv and sdiv).
 
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.
 
InstructionvisitAnd (BinaryOperator &I)
 
InstructionvisitOr (BinaryOperator &I)
 
bool sinkNotIntoLogicalOp (Instruction &I)
 
bool sinkNotIntoOtherHandOfLogicalOp (Instruction &I)
 
InstructionvisitXor (BinaryOperator &I)
 
InstructionvisitShl (BinaryOperator &I)
 
ValuereassociateShiftAmtsOfTwoSameDirectionShifts (BinaryOperator *Sh0, const SimplifyQuery &SQ, bool AnalyzeForSignBitExtraction=false)
 
InstructioncanonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract (BinaryOperator &I)
 
InstructionfoldVariableSignZeroExtensionOfVariableHighBitExtract (BinaryOperator &OldAShr)
 
InstructionvisitAShr (BinaryOperator &I)
 
InstructionvisitLShr (BinaryOperator &I)
 
InstructioncommonShiftTransforms (BinaryOperator &I)
 
InstructionvisitFCmpInst (FCmpInst &I)
 
CmpInstcanonicalizeICmpPredicate (CmpInst &I)
 If we have a comparison with a non-canonical predicate, if we can update all the users, invert the predicate and adjust all the users.
 
InstructionvisitICmpInst (ICmpInst &I)
 
InstructionFoldShiftByConstant (Value *Op0, Constant *Op1, BinaryOperator &I)
 
InstructioncommonCastTransforms (CastInst &CI)
 Implement the transforms common to all CastInst visitors.
 
InstructionvisitTrunc (TruncInst &CI)
 
InstructionvisitZExt (ZExtInst &Zext)
 
InstructionvisitSExt (SExtInst &Sext)
 
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)
 
InstructionfoldItoFPtoI (CastInst &FI)
 fpto{s/u}i({u/s}itofp(X)) --> X or zext(X) or sext(X) or trunc(X) This is safe if the intermediate type has enough bits in its mantissa to accurately represent all values of X.
 
InstructionvisitSelectInst (SelectInst &SI)
 
InstructionvisitCallInst (CallInst &CI)
 CallInst simplification.
 
InstructionvisitInvokeInst (InvokeInst &II)
 
InstructionvisitCallBrInst (CallBrInst &CBI)
 
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.
 
InstructionvisitPHINode (PHINode &PN)
 
InstructionvisitGetElementPtrInst (GetElementPtrInst &GEP)
 
InstructionvisitGEPOfGEP (GetElementPtrInst &GEP, GEPOperator *Src)
 
InstructionvisitAllocaInst (AllocaInst &AI)
 
InstructionvisitAllocSite (Instruction &FI)
 
InstructionvisitFree (CallInst &FI, Value *FreedOp)
 
InstructionvisitLoadInst (LoadInst &LI)
 
InstructionvisitStoreInst (StoreInst &SI)
 
InstructionvisitAtomicRMWInst (AtomicRMWInst &SI)
 
InstructionvisitUnconditionalBranchInst (BranchInst &BI)
 
InstructionvisitBranchInst (BranchInst &BI)
 
InstructionvisitFenceInst (FenceInst &FI)
 
InstructionvisitSwitchInst (SwitchInst &SI)
 
InstructionvisitReturnInst (ReturnInst &RI)
 
InstructionvisitUnreachableInst (UnreachableInst &I)
 
InstructionfoldAggregateConstructionIntoAggregateReuse (InsertValueInst &OrigIVI)
 Look for chain of insertvalue's that fully define an aggregate, and trace back the values inserted, see if they are all were extractvalue'd from the same source aggregate from the exact same element indexes.
 
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.
 
InstructionvisitInsertElementInst (InsertElementInst &IE)
 
InstructionvisitExtractElementInst (ExtractElementInst &EI)
 
InstructionsimplifyBinOpSplats (ShuffleVectorInst &SVI)
 
InstructionvisitShuffleVectorInst (ShuffleVectorInst &SVI)
 
InstructionvisitExtractValueInst (ExtractValueInst &EV)
 
InstructionvisitLandingPadInst (LandingPadInst &LI)
 
InstructionvisitVAEndInst (VAEndInst &I)
 
ValuepushFreezeToPreventPoisonFromPropagating (FreezeInst &FI)
 
bool freezeOtherUses (FreezeInst &FI)
 
InstructionfoldFreezeIntoRecurrence (FreezeInst &I, PHINode *PN)
 
InstructionvisitFreeze (FreezeInst &I)
 
InstructionvisitInstruction (Instruction &I)
 Specify what to return for unhandled instructions.
 
bool dominatesAllUses (const Instruction *DI, const Instruction *UI, const BasicBlock *DB) const
 True when DB dominates all uses of DI except UI.
 
bool replacedSelectWithOperand (SelectInst *SI, const ICmpInst *Icmp, const unsigned SIOpd)
 Try to replace select with select operand SIOpd in SI-ICmp sequence.
 
LoadInstcombineLoadToNewType (LoadInst &LI, Type *NewTy, const Twine &Suffix="")
 Helper to combine a load to a new type.
 
KnownFPClass computeKnownFPClass (Value *Val, FastMathFlags FMF, FPClassTest Interested=fcAllFlags, const Instruction *CtxI=nullptr, unsigned Depth=0) const
 
KnownFPClass computeKnownFPClass (Value *Val, FPClassTest Interested=fcAllFlags, const Instruction *CtxI=nullptr, unsigned Depth=0) const
 
bool fmulByZeroIsZero (Value *MulVal, FastMathFlags FMF, const Instruction *CtxI) const
 Check if fmul MulVal, +0.0 will yield +0.0 (or signed zero is ignorable).
 
ConstantgetLosslessTrunc (Constant *C, Type *TruncTy, unsigned ExtOp)
 
ConstantgetLosslessUnsignedTrunc (Constant *C, Type *TruncTy)
 
ConstantgetLosslessSignedTrunc (Constant *C, Type *TruncTy)
 
std::optional< std::pair< Intrinsic::ID, SmallVector< Value *, 3 > > > convertOrOfShiftsToFunnelShift (Instruction &Or)
 
void CreateNonTerminatorUnreachable (Instruction *InsertAt)
 Create and insert the idiom we use to indicate a block is unreachable without having to rewrite the CFG from within InstCombine.
 
InstructioneraseInstFromFunction (Instruction &I) override
 Combiner aware instruction erasure.
 
OverflowResult computeOverflow (Instruction::BinaryOps BinaryOp, bool IsSigned, Value *LHS, Value *RHS, Instruction *CxtI) const
 
bool SimplifyAssociativeOrCommutative (BinaryOperator &I)
 Performs a few simplifications for operators which are associative or commutative.
 
ValuefoldUsingDistributiveLaws (BinaryOperator &I)
 Tries to simplify binary operations which some other binary operation distributes over.
 
ValueSimplifyAddWithRemainder (BinaryOperator &I)
 Tries to simplify add operations using the definition of remainder.
 
ValueSimplifySelectsFeedingBinaryOp (BinaryOperator &I, Value *LHS, Value *RHS)
 
InstructiontryFoldInstWithCtpopWithNot (Instruction *I)
 
InstructionfoldBinOpShiftWithShift (BinaryOperator &I)
 
InstructionfoldBinOpOfSelectAndCastOfSelectCondition (BinaryOperator &I)
 Tries to simplify binops of select and cast of the select condition.
 
ValuetryFactorizationFolds (BinaryOperator &I)
 This tries to simplify binary operations by factorizing out common terms (e.
 
bool matchThreeWayIntCompare (SelectInst *SI, Value *&LHS, Value *&RHS, ConstantInt *&Less, ConstantInt *&Equal, ConstantInt *&Greater)
 Match a select chain which produces one of three values based on whether the LHS is less than, equal to, or greater than RHS respectively.
 
ValueSimplifyDemandedUseBits (Value *V, APInt DemandedMask, KnownBits &Known, unsigned Depth, Instruction *CxtI)
 Attempts to replace V with a simpler value based on the demanded bits.
 
bool SimplifyDemandedBits (Instruction *I, unsigned Op, const APInt &DemandedMask, KnownBits &Known, unsigned Depth=0) override
 This form of SimplifyDemandedBits simplifies the specified instruction operand if possible, updating it in place.
 
ValueSimplifyMultipleUseDemandedBits (Instruction *I, const APInt &DemandedMask, KnownBits &Known, unsigned Depth, Instruction *CxtI)
 Helper routine of SimplifyDemandedUseBits.
 
ValuesimplifyShrShlDemandedBits (Instruction *Shr, const APInt &ShrOp1, Instruction *Shl, const APInt &ShlOp1, const APInt &DemandedMask, KnownBits &Known)
 Helper routine of SimplifyDemandedUseBits.
 
bool SimplifyDemandedInstructionBits (Instruction &Inst)
 Tries to simplify operands to an integer instruction based on its demanded bits.
 
bool SimplifyDemandedInstructionBits (Instruction &Inst, KnownBits &Known)
 Inst is an integer instruction that SimplifyDemandedBits knows about.
 
ValueSimplifyDemandedVectorElts (Value *V, APInt DemandedElts, APInt &PoisonElts, unsigned Depth=0, bool AllowMultipleUsers=false) override
 The specified value produces a vector with any number of elements.
 
ValueSimplifyDemandedUseFPClass (Value *V, FPClassTest DemandedMask, KnownFPClass &Known, unsigned Depth, Instruction *CxtI)
 Attempts to replace V with a simpler value based on the demanded floating-point classes.
 
bool SimplifyDemandedFPClass (Instruction *I, unsigned Op, FPClassTest DemandedMask, KnownFPClass &Known, unsigned Depth=0)
 
InstructionfoldVectorBinop (BinaryOperator &Inst)
 Canonicalize the position of binops relative to shufflevector.
 
InstructionfoldVectorSelect (SelectInst &Sel)
 
InstructionfoldSelectShuffle (ShuffleVectorInst &Shuf)
 Try to fold shuffles that are the equivalent of a vector select.
 
InstructionfoldOpIntoPhi (Instruction &I, PHINode *PN)
 Given a binary operator, cast instruction, or select which has a PHI node as operand #0, see if we can fold the instruction into the PHI (which is only possible if all operands to the PHI are constants).
 
InstructionfoldBinopWithPhiOperands (BinaryOperator &BO)
 For a binary operator with 2 phi operands, try to hoist the binary operation before the phi.
 
InstructionFoldOpIntoSelect (Instruction &Op, SelectInst *SI, bool FoldWithMultiUse=false)
 Given an instruction with a select as one operand and a constant as the other operand, try to fold the binary operator into the select arguments.
 
InstructionfoldBinOpIntoSelectOrPhi (BinaryOperator &I)
 This is a convenience wrapper function for the above two functions.
 
InstructionfoldAddWithConstant (BinaryOperator &Add)
 
InstructionfoldSquareSumInt (BinaryOperator &I)
 
InstructionfoldSquareSumFP (BinaryOperator &I)
 
InstructionfoldPHIArgOpIntoPHI (PHINode &PN)
 Try to rotate an operation below a PHI node, using PHI nodes for its operands.
 
InstructionfoldPHIArgBinOpIntoPHI (PHINode &PN)
 If we have something like phi [add (a,b), add(a,c)] and if a/b/c and the adds all have a single user, turn this into a phi and a single binop.
 
InstructionfoldPHIArgInsertValueInstructionIntoPHI (PHINode &PN)
 If we have something like phi [insertvalue(a,b,0), insertvalue(c,d,0)], turn this into a phi[a,c] and phi[b,d] and a single insertvalue.
 
InstructionfoldPHIArgExtractValueInstructionIntoPHI (PHINode &PN)
 If we have something like phi [extractvalue(a,0), extractvalue(b,0)], turn this into a phi[a,b] and a single extractvalue.
 
InstructionfoldPHIArgGEPIntoPHI (PHINode &PN)
 
InstructionfoldPHIArgLoadIntoPHI (PHINode &PN)
 
InstructionfoldPHIArgZextsIntoPHI (PHINode &PN)
 TODO: This function could handle other cast types, but then it might require special-casing a cast from the 'i1' type.
 
InstructionfoldPHIArgIntToPtrToPHI (PHINode &PN)
 
bool foldIntegerTypedPHI (PHINode &PN)
 If an integer typed PHI has only one use which is an IntToPtr operation, replace the PHI with an existing pointer typed PHI if it exists.
 
void PHIArgMergedDebugLoc (Instruction *Inst, PHINode &PN)
 Helper function for FoldPHIArgXIntoPHI() to set debug location for the folded operation.
 
InstructionfoldGEPICmp (GEPOperator *GEPLHS, Value *RHS, ICmpInst::Predicate Cond, Instruction &I)
 Fold comparisons between a GEP instruction and something else.
 
InstructionfoldSelectICmp (ICmpInst::Predicate Pred, SelectInst *SI, Value *RHS, const ICmpInst &I)
 
bool foldAllocaCmp (AllocaInst *Alloca)
 
InstructionfoldCmpLoadFromIndexedGlobal (LoadInst *LI, GetElementPtrInst *GEP, GlobalVariable *GV, CmpInst &ICI, ConstantInt *AndCst=nullptr)
 This is called when we see this pattern: cmp pred (load (gep GV, ...)), cmpcst where GV is a global variable with a constant initializer.
 
InstructionfoldFCmpIntToFPConst (FCmpInst &I, Instruction *LHSI, Constant *RHSC)
 Fold fcmp ([us]itofp x, cst) if possible.
 
InstructionfoldICmpAddOpConst (Value *X, const APInt &C, ICmpInst::Predicate Pred)
 Fold "icmp pred (X+C), X".
 
InstructionfoldICmpWithCastOp (ICmpInst &ICmp)
 Handle icmp (cast x), (cast or constant).
 
InstructionfoldICmpWithZextOrSext (ICmpInst &ICmp)
 
InstructionfoldICmpUsingKnownBits (ICmpInst &Cmp)
 Try to fold the comparison based on range information we can get by checking whether bits are known to be zero or one in the inputs.
 
InstructionfoldICmpWithDominatingICmp (ICmpInst &Cmp)
 Canonicalize icmp instructions based on dominating conditions.
 
InstructionfoldICmpWithConstant (ICmpInst &Cmp)
 Fold icmp Pred X, C.
 
InstructionfoldICmpUsingBoolRange (ICmpInst &I)
 If one operand of an icmp is effectively a bool (value range of {0,1}), then try to reduce patterns based on that limit.
 
InstructionfoldICmpInstWithConstant (ICmpInst &Cmp)
 Try to fold integer comparisons with a constant operand: icmp Pred X, C where X is some kind of instruction.
 
InstructionfoldICmpInstWithConstantNotInt (ICmpInst &Cmp)
 Handle icmp with constant (but not simple integer constant) RHS.
 
InstructionfoldICmpInstWithConstantAllowPoison (ICmpInst &Cmp, const APInt &C)
 Try to fold integer comparisons with a constant operand: icmp Pred X, C where X is some kind of instruction and C is AllowPoison.
 
InstructionfoldICmpBinOp (ICmpInst &Cmp, const SimplifyQuery &SQ)
 Try to fold icmp (binop), X or icmp X, (binop).
 
InstructionfoldICmpWithMinMax (Instruction &I, MinMaxIntrinsic *MinMax, Value *Z, ICmpInst::Predicate Pred)
 Fold icmp Pred min|max(X, Y), Z.
 
InstructionfoldICmpEquality (ICmpInst &Cmp)
 
InstructionfoldIRemByPowerOfTwoToBitTest (ICmpInst &I)
 If we have: icmp eq/ne (urem/srem x, y), 0 iff y is a power-of-two, we can replace this with a bit test: icmp eq/ne (and x, (add y, -1)), 0.
 
InstructionfoldSignBitTest (ICmpInst &I)
 Fold equality-comparison between zero and any (maybe truncated) right-shift by one-less-than-bitwidth into a sign test on the original value.
 
InstructionfoldICmpWithZero (ICmpInst &Cmp)
 
ValuefoldMultiplicationOverflowCheck (ICmpInst &Cmp)
 Fold (-1 u/ x) u< y ((x * y) ?/ x) != y to @llvm.
 
InstructionfoldICmpBinOpWithConstant (ICmpInst &Cmp, BinaryOperator *BO, const APInt &C)
 Fold an icmp with BinaryOp and constant operand: icmp Pred BO, C.
 
InstructionfoldICmpSelectConstant (ICmpInst &Cmp, SelectInst *Select, ConstantInt *C)
 
InstructionfoldICmpTruncConstant (ICmpInst &Cmp, TruncInst *Trunc, const APInt &C)
 Fold icmp (trunc X), C.
 
InstructionfoldICmpTruncWithTruncOrExt (ICmpInst &Cmp, const SimplifyQuery &Q)
 Fold icmp (trunc nuw/nsw X), (trunc nuw/nsw Y).
 
InstructionfoldICmpAndConstant (ICmpInst &Cmp, BinaryOperator *And, const APInt &C)
 Fold icmp (and X, Y), C.
 
InstructionfoldICmpXorConstant (ICmpInst &Cmp, BinaryOperator *Xor, const APInt &C)
 Fold icmp (xor X, Y), C.
 
InstructionfoldICmpOrConstant (ICmpInst &Cmp, BinaryOperator *Or, const APInt &C)
 Fold icmp (or X, Y), C.
 
InstructionfoldICmpMulConstant (ICmpInst &Cmp, BinaryOperator *Mul, const APInt &C)
 Fold icmp (mul X, Y), C.
 
InstructionfoldICmpShlConstant (ICmpInst &Cmp, BinaryOperator *Shl, const APInt &C)
 Fold icmp (shl X, Y), C.
 
InstructionfoldICmpShrConstant (ICmpInst &Cmp, BinaryOperator *Shr, const APInt &C)
 Fold icmp ({al}shr X, Y), C.
 
InstructionfoldICmpSRemConstant (ICmpInst &Cmp, BinaryOperator *UDiv, const APInt &C)
 
InstructionfoldICmpUDivConstant (ICmpInst &Cmp, BinaryOperator *UDiv, const APInt &C)
 Fold icmp (udiv X, Y), C.
 
InstructionfoldICmpDivConstant (ICmpInst &Cmp, BinaryOperator *Div, const APInt &C)
 Fold icmp ({su}div X, Y), C.
 
InstructionfoldICmpSubConstant (ICmpInst &Cmp, BinaryOperator *Sub, const APInt &C)
 Fold icmp (sub X, Y), C.
 
InstructionfoldICmpAddConstant (ICmpInst &Cmp, BinaryOperator *Add, const APInt &C)
 Fold icmp (add X, Y), C.
 
InstructionfoldICmpAndConstConst (ICmpInst &Cmp, BinaryOperator *And, const APInt &C1)
 Fold icmp (and X, C2), C1.
 
InstructionfoldICmpAndShift (ICmpInst &Cmp, BinaryOperator *And, const APInt &C1, const APInt &C2)
 Fold icmp (and (sh X, Y), C2), C1.
 
InstructionfoldICmpXorShiftConst (ICmpInst &Cmp, BinaryOperator *Xor, const APInt &C)
 For power-of-2 C: ((X s>> ShiftC) ^ X) u< C --> (X + C) u< (C << 1) ((X s>> ShiftC) ^ X) u> (C - 1) --> (X + C) u> ((C << 1) - 1)
 
InstructionfoldICmpShrConstConst (ICmpInst &I, Value *ShAmt, const APInt &C1, const APInt &C2)
 Handle "(icmp eq/ne (ashr/lshr AP2, A), AP1)" -> (icmp eq/ne A, Log2(AP2/AP1)) -> (icmp eq/ne A, Log2(AP2) - Log2(AP1)).
 
InstructionfoldICmpShlConstConst (ICmpInst &I, Value *ShAmt, const APInt &C1, const APInt &C2)
 Handle "(icmp eq/ne (shl AP2, A), AP1)" -> (icmp eq/ne A, TrailingZeros(AP1) - TrailingZeros(AP2)).
 
InstructionfoldICmpBinOpEqualityWithConstant (ICmpInst &Cmp, BinaryOperator *BO, const APInt &C)
 Fold an icmp equality instruction with binary operator LHS and constant RHS: icmp eq/ne BO, C.
 
InstructionfoldICmpIntrinsicWithConstant (ICmpInst &ICI, IntrinsicInst *II, const APInt &C)
 Fold an icmp with LLVM intrinsic and constant operand: icmp Pred II, C.
 
InstructionfoldICmpEqIntrinsicWithConstant (ICmpInst &ICI, IntrinsicInst *II, const APInt &C)
 Fold an equality icmp with LLVM intrinsic and constant operand.
 
InstructionfoldICmpBitCast (ICmpInst &Cmp)
 
InstructionfoldICmpWithTrunc (ICmpInst &Cmp)
 
InstructionfoldICmpCommutative (ICmpInst::Predicate Pred, Value *Op0, Value *Op1, ICmpInst &CxtI)
 
InstructionfoldSelectOfBools (SelectInst &SI)
 
InstructionfoldSelectExtConst (SelectInst &Sel)
 
InstructionfoldSelectOpOp (SelectInst &SI, Instruction *TI, Instruction *FI)
 We have (select c, TI, FI), and we know that TI and FI have the same opcode.
 
InstructionfoldSelectIntoOp (SelectInst &SI, Value *, Value *)
 Try to fold the select into one of the operands to allow further optimization.
 
InstructionfoldSPFofSPF (Instruction *Inner, SelectPatternFlavor SPF1, Value *A, Value *B, Instruction &Outer, SelectPatternFlavor SPF2, Value *C)
 
InstructionfoldSelectInstWithICmp (SelectInst &SI, ICmpInst *ICI)
 
InstructionfoldSelectValueEquivalence (SelectInst &SI, ICmpInst &ICI)
 
bool replaceInInstruction (Value *V, Value *Old, Value *New, unsigned Depth=0)
 
ValueinsertRangeTest (Value *V, const APInt &Lo, const APInt &Hi, bool isSigned, bool Inside)
 Emit a computation of: (V >= Lo && V < Hi) if Inside is true, otherwise (V < Lo || V >= Hi).
 
bool mergeStoreIntoSuccessor (StoreInst &SI)
 Try to transform: if () { *P = v1; } else { *P = v2 } or: *P = v1; if () { *P = v2; } into a phi node with a store in the successor.
 
InstructionmatchBSwapOrBitReverse (Instruction &I, bool MatchBSwaps, bool MatchBitReversals)
 Given an initial instruction, check to see if it is the root of a bswap/bitreverse idiom.
 
InstructionSimplifyAnyMemTransfer (AnyMemTransferInst *MI)
 
InstructionSimplifyAnyMemSet (AnyMemSetInst *MI)
 
ValueEvaluateInDifferentType (Value *V, Type *Ty, bool isSigned)
 Given an expression that CanEvaluateTruncated or CanEvaluateSExtd returns true for, actually insert the code to evaluate the expression.
 
bool tryToSinkInstruction (Instruction *I, BasicBlock *DestBlock)
 Try to move the specified instruction from its current block into the beginning of DestBlock, which can only happen if it's safe to move the instruction past all of the instructions between it and the end of its block.
 
void tryToSinkInstructionDbgValues (Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock, BasicBlock *DestBlock, SmallVectorImpl< DbgVariableIntrinsic * > &DbgUsers)
 
void tryToSinkInstructionDbgVariableRecords (Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock, BasicBlock *DestBlock, SmallVectorImpl< DbgVariableRecord * > &DPUsers)
 
bool removeInstructionsBeforeUnreachable (Instruction &I)
 
void addDeadEdge (BasicBlock *From, BasicBlock *To, SmallVectorImpl< BasicBlock * > &Worklist)
 
void handleUnreachableFrom (Instruction *I, SmallVectorImpl< BasicBlock * > &Worklist)
 
void handlePotentiallyDeadBlocks (SmallVectorImpl< BasicBlock * > &Worklist)
 
void handlePotentiallyDeadSuccessors (BasicBlock *BB, BasicBlock *LiveSucc)
 
void freelyInvertAllUsersOf (Value *V, Value *IgnoredUser=nullptr)
 Freely adapt every user of V as-if V was changed to !V.
 
- Public Member Functions inherited from llvm::InstCombiner
 InstCombiner (InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI, ProfileSummaryInfo *PSI, const DataLayout &DL, LoopInfo *LI)
 
virtual ~InstCombiner ()=default
 
ValuegetFreelyInvertedImpl (Value *V, bool WillInvertAllUses, BuilderTy *Builder, bool &DoesConsume, unsigned Depth)
 Return nonnull value if V is free to invert under the condition of WillInvertAllUses.
 
ValuegetFreelyInverted (Value *V, bool WillInvertAllUses, BuilderTy *Builder, bool &DoesConsume)
 
ValuegetFreelyInverted (Value *V, bool WillInvertAllUses, BuilderTy *Builder)
 
bool isFreeToInvert (Value *V, bool WillInvertAllUses, bool &DoesConsume)
 Return true if the specified value is free to invert (apply ~ to).
 
bool isFreeToInvert (Value *V, bool WillInvertAllUses)
 
bool canFreelyInvertAllUsersOf (Instruction *V, Value *IgnoredUser)
 Given i1 V, can every user of V be freely adapted if V is changed to !V ? InstCombine's freelyInvertAllUsersOf() must be kept in sync with this fn.
 
void addToWorklist (Instruction *I)
 
AssumptionCachegetAssumptionCache () const
 
TargetLibraryInfogetTargetLibraryInfo () const
 
DominatorTreegetDominatorTree () const
 
const DataLayoutgetDataLayout () const
 
const SimplifyQuerygetSimplifyQuery () const
 
OptimizationRemarkEmittergetOptimizationRemarkEmitter () const
 
BlockFrequencyInfogetBlockFrequencyInfo () const
 
ProfileSummaryInfogetProfileSummaryInfo () const
 
LoopInfogetLoopInfo () const
 
std::optional< Instruction * > targetInstCombineIntrinsic (IntrinsicInst &II)
 
std::optional< Value * > targetSimplifyDemandedUseBitsIntrinsic (IntrinsicInst &II, APInt DemandedMask, KnownBits &Known, bool &KnownBitsComputed)
 
std::optional< Value * > targetSimplifyDemandedVectorEltsIntrinsic (IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts, APInt &UndefElts2, APInt &UndefElts3, std::function< void(Instruction *, unsigned, APInt, APInt &)> SimplifyAndSetOp)
 
InstructionInsertNewInstBefore (Instruction *New, BasicBlock::iterator Old)
 Inserts an instruction New before instruction Old.
 
InstructionInsertNewInstWith (Instruction *New, BasicBlock::iterator Old)
 Same as InsertNewInstBefore, but also sets the debug loc.
 
InstructionreplaceInstUsesWith (Instruction &I, Value *V)
 A combiner-aware RAUW-like routine.
 
InstructionreplaceOperand (Instruction &I, unsigned OpNum, Value *V)
 Replace operand of instruction and add old operand to the worklist.
 
void replaceUse (Use &U, Value *NewValue)
 Replace use and add the previously used value to the worklist.
 
virtual InstructioneraseInstFromFunction (Instruction &I)=0
 Combiner aware instruction erasure.
 
void computeKnownBits (const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
 
KnownBits computeKnownBits (const Value *V, unsigned Depth, const Instruction *CxtI) const
 
bool isKnownToBeAPowerOfTwo (const Value *V, bool OrZero=false, unsigned Depth=0, const Instruction *CxtI=nullptr)
 
bool MaskedValueIsZero (const Value *V, const APInt &Mask, unsigned Depth=0, const Instruction *CxtI=nullptr) const
 
unsigned ComputeNumSignBits (const Value *Op, unsigned Depth=0, const Instruction *CxtI=nullptr) const
 
unsigned ComputeMaxSignificantBits (const Value *Op, unsigned Depth=0, const Instruction *CxtI=nullptr) const
 
OverflowResult computeOverflowForUnsignedMul (const Value *LHS, const Value *RHS, const Instruction *CxtI, bool IsNSW=false) const
 
OverflowResult computeOverflowForSignedMul (const Value *LHS, const Value *RHS, const Instruction *CxtI) const
 
OverflowResult computeOverflowForUnsignedAdd (const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const Instruction *CxtI) const
 
OverflowResult computeOverflowForSignedAdd (const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const Instruction *CxtI) const
 
OverflowResult computeOverflowForUnsignedSub (const Value *LHS, const Value *RHS, const Instruction *CxtI) const
 
OverflowResult computeOverflowForSignedSub (const Value *LHS, const Value *RHS, const Instruction *CxtI) const
 
virtual bool SimplifyDemandedBits (Instruction *I, unsigned OpNo, const APInt &DemandedMask, KnownBits &Known, unsigned Depth=0)=0
 
virtual ValueSimplifyDemandedVectorElts (Value *V, APInt DemandedElts, APInt &UndefElts, unsigned Depth=0, bool AllowMultipleUsers=false)=0
 
bool isValidAddrSpaceCast (unsigned FromAS, unsigned ToAS) const
 
- Public Member Functions inherited from llvm::InstVisitor< InstCombinerImpl, 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)
 
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)
 
InstructionvisitFuncletPadInst (FuncletPadInst &I)
 
InstructionvisitCleanupPadInst (CleanupPadInst &I)
 
InstructionvisitCatchPadInst (CatchPadInst &I)
 
InstructionvisitFreezeInst (FreezeInst &I)
 
InstructionvisitDbgDeclareInst (DbgDeclareInst &I)
 
InstructionvisitDbgValueInst (DbgValueInst &I)
 
InstructionvisitDbgVariableIntrinsic (DbgVariableIntrinsic &I)
 
InstructionvisitDbgLabelInst (DbgLabelInst &I)
 
InstructionvisitDbgInfoIntrinsic (DbgInfoIntrinsic &I)
 
InstructionvisitMemSetInst (MemSetInst &I)
 
InstructionvisitMemSetInlineInst (MemSetInlineInst &I)
 
InstructionvisitMemCpyInst (MemCpyInst &I)
 
InstructionvisitMemCpyInlineInst (MemCpyInlineInst &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)
 
InstructionvisitCallBrInst (CallBrInst &I)
 
InstructionvisitReturnInst (ReturnInst &I)
 
InstructionvisitBranchInst (BranchInst &I)
 
InstructionvisitSwitchInst (SwitchInst &I)
 
InstructionvisitIndirectBrInst (IndirectBrInst &I)
 
InstructionvisitResumeInst (ResumeInst &I)
 
InstructionvisitUnreachableInst (UnreachableInst &I)
 
InstructionvisitCleanupReturnInst (CleanupReturnInst &I)
 
InstructionvisitCatchReturnInst (CatchReturnInst &I)
 
InstructionvisitCatchSwitchInst (CatchSwitchInst &I)
 
InstructionvisitTerminator (Instruction &I)
 
InstructionvisitCastInst (CastInst &I)
 
InstructionvisitUnaryOperator (UnaryOperator &I)
 
InstructionvisitBinaryOperator (BinaryOperator &I)
 
InstructionvisitCmpInst (CmpInst &I)
 
InstructionvisitUnaryInstruction (UnaryInstruction &I)
 
InstructionvisitCallBase (CallBase &I)
 
void visitInstruction (Instruction &I)
 

Additional Inherited Members

- Public Types inherited from llvm::InstCombiner
using BuilderTy = IRBuilder< TargetFolder, IRBuilderCallbackInserter >
 An IRBuilder that automatically inserts new instructions into the worklist.
 
- Static Public Member Functions inherited from llvm::InstCombiner
static ValuepeekThroughBitcast (Value *V, bool OneUseOnly=false)
 Return the source operand of a potentially bitcasted value while optionally checking if it has one use.
 
static unsigned getComplexity (Value *V)
 Assign a complexity or rank value to LLVM Values.
 
static bool isCanonicalPredicate (CmpInst::Predicate Pred)
 Predicate canonicalization reduces the number of patterns that need to be matched by other transforms.
 
static ConstantAddOne (Constant *C)
 Add one to a Constant.
 
static ConstantSubOne (Constant *C)
 Subtract one from a Constant.
 
static std::optional< std::pair< CmpInst::Predicate, Constant * > > getFlippedStrictnessPredicateAndConstant (CmpInst::Predicate Pred, Constant *C)
 
static bool shouldAvoidAbsorbingNotIntoSelect (const SelectInst &SI)
 
static ConstantgetSafeVectorConstantForBinop (BinaryOperator::BinaryOps Opcode, Constant *In, bool IsRHSConstant)
 Some binary operators require special handling to avoid poison and undefined behavior.
 
- Public Attributes inherited from llvm::InstCombiner
uint64_t MaxArraySizeForCombine = 0
 Maximum size of array considered when transforming.
 
BuilderTyBuilder
 
- Protected Attributes inherited from llvm::InstCombiner
InstructionWorklistWorklist
 A worklist of the instructions that need to be simplified.
 
const bool MinimizeSize
 
AAResultsAA
 
AssumptionCacheAC
 
TargetLibraryInfoTLI
 
DominatorTreeDT
 
const DataLayoutDL
 
SimplifyQuery SQ
 
OptimizationRemarkEmitterORE
 
BlockFrequencyInfoBFI
 
BranchProbabilityInfoBPI
 
ProfileSummaryInfoPSI
 
DomConditionCache DC
 
LoopInfoLI
 
bool MadeIRChange = false
 
SmallDenseSet< std::pair< BasicBlock *, BasicBlock * >, 8 > DeadEdges
 Edges that are known to never be taken.
 
SmallDenseMap< BasicBlock *, SmallVector< BasicBlock * >, 8 > PredOrder
 Order of predecessors to canonicalize phi nodes towards.
 

Detailed Description

Definition at line 62 of file InstCombineInternal.h.

Constructor & Destructor Documentation

◆ InstCombinerImpl()

llvm::InstCombinerImpl::InstCombinerImpl ( InstructionWorklist Worklist,
BuilderTy Builder,
bool  MinimizeSize,
AAResults AA,
AssumptionCache AC,
TargetLibraryInfo TLI,
TargetTransformInfo TTI,
DominatorTree DT,
OptimizationRemarkEmitter ORE,
BlockFrequencyInfo BFI,
BranchProbabilityInfo BPI,
ProfileSummaryInfo PSI,
const DataLayout DL,
LoopInfo LI 
)
inline

Definition at line 66 of file InstCombineInternal.h.

◆ ~InstCombinerImpl()

virtual llvm::InstCombinerImpl::~InstCombinerImpl ( )
virtualdefault

Member Function Documentation

◆ addDeadEdge()

void InstCombinerImpl::addDeadEdge ( BasicBlock From,
BasicBlock To,
SmallVectorImpl< BasicBlock * > &  Worklist 
)

◆ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract()

Instruction * InstCombinerImpl::canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract ( BinaryOperator I)

◆ canonicalizeICmpPredicate()

CmpInst * InstCombinerImpl::canonicalizeICmpPredicate ( CmpInst I)

If we have a comparison with a non-canonical predicate, if we can update all the users, invert the predicate and adjust all the users.

Definition at line 6762 of file InstCombineCompares.cpp.

References llvm::InstCombiner::canFreelyInvertAllUsersOf(), freelyInvertAllUsersOf(), llvm::CmpInst::getInversePredicate(), I, and llvm::InstCombiner::isCanonicalPredicate().

Referenced by visitICmpInst().

◆ combineLoadToNewType()

LoadInst * InstCombinerImpl::combineLoadToNewType ( LoadInst LI,
Type NewTy,
const Twine Suffix = "" 
)

Helper to combine a load to a new type.

This just does the work of combining a load to a new type. It handles metadata, etc., and returns the new instruction. The NewTy should be the loaded value type. This will convert it to a pointer, cast the operand to that pointer type, load it, etc.

Note that this will create all of the instructions with whatever insert point the InstCombinerImpl currently is using.

Definition at line 557 of file InstCombineLoadStoreAlloca.cpp.

References assert(), llvm::InstCombiner::Builder, llvm::copyMetadataForLoad(), llvm::IRBuilderBase::CreateAlignedLoad(), isSupportedAtomicType(), llvm::InstCombiner::LI, and llvm::LoadInst::setAtomic().

Referenced by combineLoadToOperationType(), and unpackLoadToAggregate().

◆ commonCastTransforms()

Instruction * InstCombinerImpl::commonCastTransforms ( CastInst CI)

◆ commonIDivTransforms()

Instruction * InstCombinerImpl::commonIDivTransforms ( BinaryOperator I)

This function implements the transforms common to both integer division instructions (udiv and sdiv).

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

Definition at line 1117 of file InstCombineMulDivRem.cpp.

References A, assert(), B, llvm::InstCombiner::Builder, llvm::BinaryOperator::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpULT(), llvm::IRBuilderBase::CreateShl(), foldBinOpIntoSelectOrPhi(), foldBinopWithPhiOperands(), foldIDivShl(), FoldOpIntoSelect(), llvm::APInt::getBitWidth(), llvm::APInt::getOneBitSet(), llvm::APInt::getZExtValue(), llvm::Instruction::hasNoSignedWrap(), hasNoUnsignedWrap(), I, llvm::APInt::isAllOnes(), llvm::Type::isIntOrIntVectorTy(), isMultiple(), llvm::APInt::isZero(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_NSWAddLike(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_NUWAddLike(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Mul, multiplyOverflows(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::Instruction::setIsExact(), SimplifyDemandedInstructionBits(), simplifyDivRemOfSelectWithZeroOp(), simplifyValueKnownNonZero(), llvm::APInt::udiv(), llvm::APInt::ule(), llvm::APInt::ult(), X, and Y.

Referenced by visitSDiv(), and visitUDiv().

◆ commonIRemTransforms()

Instruction * InstCombinerImpl::commonIRemTransforms ( BinaryOperator I)

◆ commonShiftTransforms()

Instruction * InstCombinerImpl::commonShiftTransforms ( BinaryOperator I)

◆ computeKnownFPClass() [1/2]

KnownFPClass llvm::InstCombinerImpl::computeKnownFPClass ( Value Val,
FastMathFlags  FMF,
FPClassTest  Interested = fcAllFlags,
const Instruction CtxI = nullptr,
unsigned  Depth = 0 
) const
inline

Definition at line 202 of file InstCombineInternal.h.

References llvm::computeKnownFPClass(), and llvm::Depth.

Referenced by foldSelectIntoOp(), and SimplifyDemandedUseFPClass().

◆ computeKnownFPClass() [2/2]

KnownFPClass llvm::InstCombinerImpl::computeKnownFPClass ( Value Val,
FPClassTest  Interested = fcAllFlags,
const Instruction CtxI = nullptr,
unsigned  Depth = 0 
) const
inline

Definition at line 211 of file InstCombineInternal.h.

References llvm::computeKnownFPClass(), and llvm::Depth.

◆ computeOverflow()

OverflowResult InstCombinerImpl::computeOverflow ( Instruction::BinaryOps  BinaryOp,
bool  IsSigned,
Value LHS,
Value RHS,
Instruction CxtI 
) const

◆ convertOrOfShiftsToFunnelShift()

std::optional< std::pair< Intrinsic::ID, SmallVector< Value *, 3 > > > InstCombinerImpl::convertOrOfShiftsToFunnelShift ( Instruction Or)

◆ CreateNonTerminatorUnreachable()

void llvm::InstCombinerImpl::CreateNonTerminatorUnreachable ( Instruction InsertAt)
inline

Create and insert the idiom we use to indicate a block is unreachable without having to rewrite the CFG from within InstCombine.

Definition at line 460 of file InstCombineInternal.h.

References Align, llvm::Value::getContext(), llvm::ilist_node_impl< OptionsT >::getIterator(), and SI().

Referenced by visitCallInst(), visitFree(), and visitLoadInst().

◆ dominatesAllUses()

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

True when DB dominates all uses of DI except UI.

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

UI must be in the same block as DI. The routine checks that the DI parent and DB are different.

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 6215 of file InstCombineCompares.cpp.

References assert(), llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::Instruction::getParent(), and llvm::Value::users().

Referenced by replacedSelectWithOperand().

◆ eraseInstFromFunction()

Instruction * llvm::InstCombinerImpl::eraseInstFromFunction ( Instruction I)
inlineoverridevirtual

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.

Implements llvm::InstCombiner.

Definition at line 473 of file InstCombineInternal.h.

References assert(), llvm::dbgs(), I, LLVM_DEBUG, and llvm::salvageDebugInfo().

Referenced by combineLoadToOperationType(), foldAllocaCmp(), foldIntegerTypedPHI(), foldMultiplicationOverflowCheck(), foldOpIntoPhi(), handleUnreachableFrom(), mergeStoreIntoSuccessor(), processUGT_ADDCST_ADD(), removeInstructionsBeforeUnreachable(), removeTriviallyEmptyRange(), run(), visitAllocaInst(), visitAllocSite(), visitCallInst(), visitFenceInst(), visitFree(), visitICmpInst(), and visitStoreInst().

◆ EvaluateInDifferentType()

Value * InstCombinerImpl::EvaluateInDifferentType ( Value V,
Type Ty,
bool  isSigned 
)

◆ fmulByZeroIsZero()

bool llvm::InstCombinerImpl::fmulByZeroIsZero ( Value MulVal,
FastMathFlags  FMF,
const Instruction CtxI 
) const

Check if fmul MulVal, +0.0 will yield +0.0 (or signed zero is ignorable).

◆ foldAddWithConstant()

Instruction * InstCombinerImpl::foldAddWithConstant ( BinaryOperator Add)

Definition at line 851 of file InstCombineAddSub.cpp.

References llvm::Add, llvm::InstCombiner::AddOne(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::InstCombiner::computeKnownBits(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateIsNotNeg(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateShl(), foldBinOpIntoSelectOrPhi(), llvm::ConstantExpr::getAdd(), llvm::APInt::getHighBitsSet(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), llvm::isKnownNonZero(), llvm::APInt::isMask(), llvm::APInt::isMinSignedValue(), llvm::APInt::isPowerOf2(), llvm::APInt::isSignMask(), llvm::APInt::logBase2(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_DisjointOr(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZExt(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::Instruction::setHasNoSignedWrap(), llvm::APInt::sext(), llvm::InstCombiner::SQ, llvm::InstCombiner::SubOne(), X, Y, and llvm::KnownBits::Zero.

Referenced by visitAdd().

◆ foldAggregateConstructionIntoAggregateReuse()

Instruction * InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse ( InsertValueInst OrigIVI)

Look for chain of insertvalue's that fully define an aggregate, and trace back the values inserted, see if they are all were extractvalue'd from the same source aggregate from the exact same element indexes.

If they were, just reuse the source aggregate. This potentially deals with PHI indirections.

When analyzing the value that was inserted into an aggregate, we did not manage to find defining extractvalue instruction to analyze.

When analyzing the value that was inserted into an aggregate, we did manage to find defining extractvalue instruction[s], and everything matched perfectly - aggregate type, element insertion/extraction index.

When analyzing the value that was inserted into an aggregate, we did manage to find defining extractvalue instruction, but there was a mismatch: either the source type from which the extraction was didn't match the aggregate type into which the insertion was, or the extraction/insertion channels mismatched, or different elements had different source aggregates.

Definition at line 863 of file InstCombineVectorOps.cpp.

References llvm::Type::ArrayTyID, assert(), llvm::Depth, llvm::Value::DoPHITranslation(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::enumerate(), llvm::ArrayRef< T >::front(), llvm::Type::getArrayNumElements(), llvm::BasicBlock::getParent(), llvm::Type::getStructNumElements(), llvm::Value::getType(), llvm::Type::getTypeID(), I, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::is_contained(), IV, llvm_unreachable, llvm::pred_empty(), llvm::predecessors(), llvm::InstCombiner::replaceInstUsesWith(), llvm::ArrayRef< T >::size(), llvm::SmallVectorBase< Size_T >::size(), and llvm::Type::StructTyID.

Referenced by visitInsertValueInst().

◆ foldAllocaCmp()

bool InstCombinerImpl::foldAllocaCmp ( AllocaInst Alloca)

◆ foldBinOpIntoSelectOrPhi()

Instruction * InstCombinerImpl::foldBinOpIntoSelectOrPhi ( BinaryOperator I)

This is a convenience wrapper function for the above two functions.

Definition at line 1985 of file InstructionCombining.cpp.

References foldOpIntoPhi(), FoldOpIntoSelect(), and I.

Referenced by commonIDivTransforms(), foldAddWithConstant(), FoldShiftByConstant(), visitAnd(), visitFAdd(), visitFMul(), visitMul(), visitOr(), and visitXor().

◆ foldBinOpOfSelectAndCastOfSelectCondition()

Instruction * InstCombinerImpl::foldBinOpOfSelectAndCastOfSelectCondition ( BinaryOperator I)

◆ foldBinOpShiftWithShift()

Instruction * InstCombinerImpl::foldBinOpShiftWithShift ( BinaryOperator I)

◆ foldBinopWithPhiOperands()

Instruction * InstCombinerImpl::foldBinopWithPhiOperands ( BinaryOperator BO)

◆ foldCmpLoadFromIndexedGlobal()

Instruction * InstCombinerImpl::foldCmpLoadFromIndexedGlobal ( LoadInst LI,
GetElementPtrInst GEP,
GlobalVariable GV,
CmpInst ICI,
ConstantInt AndCst = nullptr 
)

This is called when 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 111 of file InstCombineCompares.cpp.

References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldExtractValueInstruction(), llvm::countr_zero(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpNE(), llvm::IRBuilderBase::CreateIntCast(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateTrunc(), llvm::InstCombiner::DL, llvm::SmallVectorBase< Size_T >::empty(), End, GEP, llvm::IRBuilderBase::getFalse(), llvm::DataLayout::getIndexType(), llvm::GlobalVariable::getInitializer(), llvm::Type::getIntegerBitWidth(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::DataLayout::getSmallestLegalIntType(), llvm::IRBuilderBase::getTrue(), getType(), llvm::DataLayout::getTypeAllocSize(), llvm::GlobalValue::getValueType(), llvm::GlobalVariable::hasDefinitiveInitializer(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, Idx, llvm::GlobalVariable::isConstant(), llvm::InstCombiner::LI, llvm::InstCombiner::MaxArraySizeForCombine, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), and llvm::InstCombiner::TLI.

Referenced by foldICmpAndConstant(), foldICmpInstWithConstantNotInt(), and visitFCmpInst().

◆ foldFCmpIntToFPConst()

Instruction * InstCombinerImpl::foldFCmpIntToFPConst ( FCmpInst I,
Instruction LHSI,
Constant RHSC 
)

◆ foldFMulReassoc()

Instruction * InstCombinerImpl::foldFMulReassoc ( BinaryOperator I)

◆ foldFreezeIntoRecurrence()

Instruction * InstCombinerImpl::foldFreezeIntoRecurrence ( FreezeInst I,
PHINode PN 
)

◆ foldGEPICmp()

Instruction * InstCombinerImpl::foldGEPICmp ( GEPOperator GEPLHS,
Value RHS,
ICmpInst::Predicate  Cond,
Instruction I 
)

◆ foldICmpAddConstant()

Instruction * InstCombinerImpl::foldICmpAddConstant ( ICmpInst Cmp,
BinaryOperator Add,
const APInt C 
)

◆ foldICmpAddOpConst()

Instruction * InstCombinerImpl::foldICmpAddOpConst ( Value X,
const APInt C,
ICmpInst::Predicate  Pred 
)

◆ foldICmpAndConstant()

Instruction * InstCombinerImpl::foldICmpAndConstant ( ICmpInst Cmp,
BinaryOperator And,
const APInt C 
)

◆ foldICmpAndConstConst()

Instruction * InstCombinerImpl::foldICmpAndConstConst ( ICmpInst Cmp,
BinaryOperator And,
const APInt C1 
)

Fold icmp (and X, C2), C1.

Definition at line 1743 of file InstCombineCompares.cpp.

References A, llvm::And, B, llvm::APFloat::bitcastToAPInt(), llvm::InstCombiner::Builder, llvm::InstCombiner::computeKnownBits(), llvm::KnownBits::countMinLeadingZeros(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::createIsFPClass(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateShl(), llvm::fcAllFlags, llvm::fcInf, llvm::fcNan, foldICmpAndShift(), llvm::APInt::getBitWidth(), llvm::Type::getFltSemantics(), llvm::APInt::getHighBitsSet(), llvm::APFloat::getInf(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, llvm::Type::isIEEELikeFPTy(), llvm::APInt::isNegatedPowerOf2(), llvm::APInt::isNegative(), llvm::APInt::isSignMask(), llvm::APInt::isZero(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Or, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), X, and llvm::APInt::zext().

Referenced by foldICmpAndConstant().

◆ foldICmpAndShift()

Instruction * InstCombinerImpl::foldICmpAndShift ( ICmpInst Cmp,
BinaryOperator And,
const APInt C1,
const APInt C2 
)

◆ foldICmpBinOp()

Instruction * InstCombinerImpl::foldICmpBinOp ( ICmpInst I,
const SimplifyQuery SQ 
)

Try to fold icmp (binop), X or icmp X, (binop).

TODO: A large part of this logic is duplicated in InstSimplify's simplifyICmpWithBinOp(). We should be able to share that and avoid the code duplication.

Definition at line 4778 of file InstCombineCompares.cpp.

References A, llvm::APInt::abs(), assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::InstCombiner::computeKnownBits(), llvm::KnownBits::countMaxTrailingZeros(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateSub(), D, foldICmpAndXX(), foldICmpOrXX(), foldICmpWithTruncSignExtendedVal(), foldICmpXNegX(), foldICmpXorXX(), foldMultiplicationOverflowCheck(), foldShiftIntoShiftInAnotherHandOfAndInICmp(), llvm::Constant::getAllOnesValue(), llvm::ConstantInt::getFalse(), llvm::CmpInst::getFlippedStrictnessPredicate(), llvm::Constant::getIntegerValue(), llvm::APInt::getLowBitsSet(), llvm::ConstantExpr::getNeg(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ICmpInst::getSignedPredicate(), llvm::ConstantExpr::getSub(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::ICmpInst::getUnsignedPredicate(), llvm::SimplifyQuery::getWithInstruction(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::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::Instruction::isExact(), llvm::isKnownNonZero(), llvm::APInt::isNegative(), llvm::CmpInst::isSigned(), llvm::CmpInst::isUnsigned(), llvm::APInt::isZero(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AddLike(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LowBitMask(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NonNegative(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::KnownBits::One, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::SQ, llvm::APInt::uge(), llvm::APInt::ule(), X, and Y.

Referenced by visitICmpInst().

◆ foldICmpBinOpEqualityWithConstant()

Instruction * InstCombinerImpl::foldICmpBinOpEqualityWithConstant ( ICmpInst Cmp,
BinaryOperator BO,
const APInt C 
)

◆ foldICmpBinOpWithConstant()

Instruction * InstCombinerImpl::foldICmpBinOpWithConstant ( ICmpInst Cmp,
BinaryOperator BO,
const APInt C 
)

◆ foldICmpBitCast()

Instruction * InstCombinerImpl::foldICmpBitCast ( ICmpInst Cmp)

◆ foldICmpCommutative()

Instruction * InstCombinerImpl::foldICmpCommutative ( ICmpInst::Predicate  Pred,
Value Op0,
Value Op1,
ICmpInst CxtI 
)

◆ foldICmpDivConstant()

Instruction * InstCombinerImpl::foldICmpDivConstant ( ICmpInst Cmp,
BinaryOperator Div,
const APInt C 
)

◆ foldICmpEqIntrinsicWithConstant()

Instruction * InstCombinerImpl::foldICmpEqIntrinsicWithConstant ( ICmpInst ICI,
IntrinsicInst II,
const APInt C 
)

◆ foldICmpEquality()

Instruction * InstCombinerImpl::foldICmpEquality ( ICmpInst Cmp)

Definition at line 5453 of file InstCombineCompares.cpp.

References A, llvm::Add, llvm::And, B, llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APInt::countr_one(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateXor(), D, foldICmpIntrinsicWithIntrinsic(), llvm::APInt::getBitWidth(), llvm::ConstantInt::getBitWidth(), llvm::IRBuilderBase::getInt(), llvm::CmpInst::getInversePredicate(), llvm::APInt::getLimitedValue(), llvm::ConstantInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LowBitMask(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Unless(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), NC, X, llvm::Xor, Y, and llvm::APInt::zext().

Referenced by visitICmpInst().

◆ foldICmpInstWithConstant()

Instruction * InstCombinerImpl::foldICmpInstWithConstant ( ICmpInst Cmp)

◆ foldICmpInstWithConstantAllowPoison()

Instruction * InstCombinerImpl::foldICmpInstWithConstantAllowPoison ( ICmpInst Cmp,
const APInt C 
)

Try to fold integer comparisons with a constant operand: icmp Pred X, C where X is some kind of instruction and C is AllowPoison.

TODO: Move more folds which allow poison to this function.

Definition at line 3746 of file InstCombineCompares.cpp.

References llvm::CallingConv::C.

Referenced by foldICmpInstWithConstant().

◆ foldICmpInstWithConstantNotInt()

Instruction * InstCombinerImpl::foldICmpInstWithConstantNotInt ( ICmpInst Cmp)

◆ foldICmpIntrinsicWithConstant()

Instruction * InstCombinerImpl::foldICmpIntrinsicWithConstant ( ICmpInst ICI,
IntrinsicInst II,
const APInt C 
)

◆ foldICmpMulConstant()

Instruction * InstCombinerImpl::foldICmpMulConstant ( ICmpInst Cmp,
BinaryOperator Mul,
const APInt C 
)

◆ foldICmpOrConstant()

Instruction * InstCombinerImpl::foldICmpOrConstant ( ICmpInst Cmp,
BinaryOperator Or,
const APInt C 
)

◆ foldICmpSelectConstant()

Instruction * InstCombinerImpl::foldICmpSelectConstant ( ICmpInst Cmp,
SelectInst Select,
ConstantInt C 
)

◆ foldICmpShlConstant()

Instruction * InstCombinerImpl::foldICmpShlConstant ( ICmpInst Cmp,
BinaryOperator Shl,
const APInt C 
)

◆ foldICmpShlConstConst()

Instruction * InstCombinerImpl::foldICmpShlConstConst ( ICmpInst I,
Value ShAmt,
const APInt C1,
const APInt C2 
)

Handle "(icmp eq/ne (shl AP2, A), AP1)" -> (icmp eq/ne A, TrailingZeros(AP1) - TrailingZeros(AP2)).

Definition at line 1021 of file InstCombineCompares.cpp.

References A, assert(), llvm::APInt::countr_zero(), llvm::APInt::getBitWidth(), llvm::CmpInst::getInversePredicate(), llvm::Constant::getNullValue(), I, llvm::APInt::isZero(), LHS, llvm::InstCombiner::replaceInstUsesWith(), RHS, and llvm::APInt::shl().

Referenced by foldICmpShlConstant().

◆ foldICmpShrConstant()

Instruction * InstCombinerImpl::foldICmpShrConstant ( ICmpInst Cmp,
BinaryOperator Shr,
const APInt C 
)

◆ foldICmpShrConstConst()

Instruction * InstCombinerImpl::foldICmpShrConstConst ( ICmpInst I,
Value ShAmt,
const APInt C1,
const APInt C2 
)

◆ foldICmpSRemConstant()

Instruction * InstCombinerImpl::foldICmpSRemConstant ( ICmpInst Cmp,
BinaryOperator UDiv,
const APInt C 
)

◆ foldICmpSubConstant()

Instruction * InstCombinerImpl::foldICmpSubConstant ( ICmpInst Cmp,
BinaryOperator Sub,
const APInt C 
)

◆ foldICmpTruncConstant()

Instruction * InstCombinerImpl::foldICmpTruncConstant ( ICmpInst Cmp,
TruncInst Trunc,
const APInt C 
)

◆ foldICmpTruncWithTruncOrExt()

Instruction * InstCombinerImpl::foldICmpTruncWithTruncOrExt ( ICmpInst Cmp,
const SimplifyQuery Q 
)

◆ foldICmpUDivConstant()

Instruction * InstCombinerImpl::foldICmpUDivConstant ( ICmpInst Cmp,
BinaryOperator UDiv,
const APInt C 
)

◆ foldICmpUsingBoolRange()

Instruction * InstCombinerImpl::foldICmpUsingBoolRange ( ICmpInst I)

◆ foldICmpUsingKnownBits()

Instruction * InstCombinerImpl::foldICmpUsingKnownBits ( ICmpInst Cmp)

Try to fold the comparison based on range information we can get by checking whether bits are known to be zero or one in the inputs.

Definition at line 6318 of file InstCombineCompares.cpp.

References _, A, assert(), B, llvm::BitWidth, llvm::APInt::ceilLogBase2(), llvm::KnownBits::countMinTrailingZeros(), llvm::APInt::countr_zero(), llvm::SimplifyQuery::DC, llvm::InstCombiner::DC, llvm::InstCombiner::DL, llvm::SelectPatternResult::Flavor, llvm::APInt::getActiveBits(), llvm::APInt::getAllOnes(), llvm::ConstantInt::getBool(), llvm::KnownBits::getConstant(), getDemandedBitsLHSMask(), llvm::ConstantInt::getFalse(), llvm::Constant::getIntegerValue(), llvm::CmpInst::getInversePredicate(), llvm::KnownBits::getMaxValue(), llvm::KnownBits::getMinValue(), llvm::Constant::getNullValue(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::KnownBits::getSignedMaxValue(), llvm::KnownBits::getSignedMinValue(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), 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::KnownBits::isConstant(), llvm::Type::isIntOrIntVectorTy(), llvm::SelectPatternResult::isMinOrMax(), llvm::APInt::isNegative(), llvm::APInt::isPowerOf2(), llvm::KnownBits::isZero(), LHS, llvm_unreachable, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_MaxOrMin(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::make_scope_exit(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), llvm::KnownBits::One, llvm::InstCombiner::replaceInstUsesWith(), SimplifyDemandedBits(), llvm::APInt::sle(), llvm::APInt::slt(), llvm::InstCombiner::SQ, llvm::APInt::ule(), llvm::APInt::ult(), X, and llvm::KnownBits::Zero.

Referenced by visitICmpInst().

◆ foldICmpWithCastOp()

Instruction * InstCombinerImpl::foldICmpWithCastOp ( ICmpInst ICmp)

◆ foldICmpWithConstant()

Instruction * InstCombinerImpl::foldICmpWithConstant ( ICmpInst Cmp)

Fold icmp Pred X, C.

TODO: This code structure does not make sense. The saturating add fold should be moved to some other helper and extended as noted below (it is also possible that code has been made unnecessary - do we canonicalize IR to overflow/saturating intrinsics or not?).

Definition at line 1284 of file InstCombineCompares.cpp.

References A, llvm::PHINode::addIncoming(), llvm::all_of(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldCompareInstOperands(), llvm::IRBuilderBase::CreatePHI(), llvm::InstCombiner::DL, llvm::CmpInst::ICMP_UGT, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), processUGT_ADDCST_ADD(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::IRBuilderBase::SetInsertPoint(), tryFoldInstWithCtpopWithNot(), and llvm::zip().

Referenced by visitICmpInst().

◆ foldICmpWithDominatingICmp()

Instruction * InstCombinerImpl::foldICmpWithDominatingICmp ( ICmpInst Cmp)

◆ foldICmpWithMinMax()

Instruction * InstCombinerImpl::foldICmpWithMinMax ( Instruction I,
MinMaxIntrinsic MinMax,
Value Z,
ICmpInst::Predicate  Pred 
)

◆ foldICmpWithTrunc()

Instruction * InstCombinerImpl::foldICmpWithTrunc ( ICmpInst Cmp)

◆ foldICmpWithZero()

Instruction * InstCombinerImpl::foldICmpWithZero ( ICmpInst Cmp)

◆ foldICmpWithZextOrSext()

Instruction * InstCombinerImpl::foldICmpWithZextOrSext ( ICmpInst ICmp)

◆ foldICmpXorConstant()

Instruction * InstCombinerImpl::foldICmpXorConstant ( ICmpInst Cmp,
BinaryOperator Xor,
const APInt C 
)

◆ foldICmpXorShiftConst()

Instruction * InstCombinerImpl::foldICmpXorShiftConst ( ICmpInst Cmp,
BinaryOperator Xor,
const APInt C 
)

◆ foldIntegerTypedPHI()

bool InstCombinerImpl::foldIntegerTypedPHI ( PHINode PN)

◆ foldIRemByPowerOfTwoToBitTest()

Instruction * InstCombinerImpl::foldIRemByPowerOfTwoToBitTest ( ICmpInst I)

◆ foldItoFPtoI()

Instruction * InstCombinerImpl::foldItoFPtoI ( CastInst FI)

fpto{s/u}i({u/s}itofp(X)) --> X or zext(X) or sext(X) or trunc(X) This is safe if the intermediate type has enough bits in its mantissa to accurately represent all values of X.

For example, this won't work with i64 -> float -> i64.

Definition at line 1912 of file InstCombineCasts.cpp.

References assert(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), isKnownExactCastIntToFP(), llvm::InstCombiner::replaceInstUsesWith(), and X.

Referenced by visitFPToSI(), and visitFPToUI().

◆ foldMultiplicationOverflowCheck()

Value * InstCombinerImpl::foldMultiplicationOverflowCheck ( ICmpInst I)

◆ foldOpIntoPhi()

Instruction * InstCombinerImpl::foldOpIntoPhi ( Instruction I,
PHINode PN 
)

◆ FoldOpIntoSelect()

Instruction * InstCombinerImpl::FoldOpIntoSelect ( Instruction Op,
SelectInst SI,
bool  FoldWithMultiUse = false 
)

Given an instruction with a select as one operand and a constant as the other operand, try to fold the binary operator into the select arguments.

This also works for Cast instructions, which obviously do not have a second operand.

Definition at line 1683 of file InstructionCombining.cpp.

References constantFoldOperationIntoSelectOperand(), llvm::SelectInst::Create(), and foldOperationIntoSelectOperand().

Referenced by commonCastTransforms(), commonIDivTransforms(), commonIRemTransforms(), commonShiftTransforms(), foldBinOpIntoSelectOrPhi(), visitCallInst(), visitExtractElementInst(), visitExtractValueInst(), visitFCmpInst(), visitFDiv(), visitFSub(), and visitSub().

◆ foldPHIArgBinOpIntoPHI()

Instruction * InstCombinerImpl::foldPHIArgBinOpIntoPHI ( PHINode PN)

◆ foldPHIArgExtractValueInstructionIntoPHI()

Instruction * InstCombinerImpl::foldPHIArgExtractValueInstructionIntoPHI ( PHINode PN)

◆ foldPHIArgGEPIntoPHI()

Instruction * InstCombinerImpl::foldPHIArgGEPIntoPHI ( PHINode PN)

◆ foldPHIArgInsertValueInstructionIntoPHI()

Instruction * InstCombinerImpl::foldPHIArgInsertValueInstructionIntoPHI ( PHINode PN)

◆ foldPHIArgIntToPtrToPHI()

Instruction * InstCombinerImpl::foldPHIArgIntToPtrToPHI ( PHINode PN)

◆ foldPHIArgLoadIntoPHI()

Instruction * InstCombinerImpl::foldPHIArgLoadIntoPHI ( PHINode PN)

◆ foldPHIArgOpIntoPHI()

Instruction * InstCombinerImpl::foldPHIArgOpIntoPHI ( PHINode PN)

◆ foldPHIArgZextsIntoPHI()

Instruction * InstCombinerImpl::foldPHIArgZextsIntoPHI ( PHINode Phi)

TODO: This function could handle other cast types, but then it might require special-casing a cast from the 'i1' type.

See the comment in FoldPHIArgOpIntoPHI() about pessimizing illegal integer types.

Definition at line 789 of file InstCombinePHI.cpp.

References llvm::PHINode::addIncoming(), llvm::CallingConv::C, llvm::PHINode::Create(), llvm::CastInst::CreateZExtOrBitCast(), getLosslessUnsignedTrunc(), I, llvm::InstCombiner::InsertNewInstBefore(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by visitPHINode().

◆ foldPowiReassoc()

Instruction * InstCombinerImpl::foldPowiReassoc ( BinaryOperator I)

◆ foldSelectExtConst()

Instruction * llvm::InstCombinerImpl::foldSelectExtConst ( SelectInst Sel)

◆ foldSelectICmp()

Instruction * InstCombinerImpl::foldSelectICmp ( ICmpInst::Predicate  Pred,
SelectInst SI,
Value RHS,
const ICmpInst I 
)

◆ foldSelectInstWithICmp()

Instruction * llvm::InstCombinerImpl::foldSelectInstWithICmp ( SelectInst SI,
ICmpInst ICI 
)

◆ foldSelectIntoOp()

Instruction * InstCombinerImpl::foldSelectIntoOp ( SelectInst SI,
Value TrueVal,
Value FalseVal 
)

◆ foldSelectOfBools()

Instruction * llvm::InstCombinerImpl::foldSelectOfBools ( SelectInst SI)

◆ foldSelectOpOp()

Instruction * InstCombinerImpl::foldSelectOpOp ( SelectInst SI,
Instruction TI,
Instruction FI 
)

◆ foldSelectShuffle()

Instruction * InstCombinerImpl::foldSelectShuffle ( ShuffleVectorInst Shuf)

◆ foldSelectValueEquivalence()

Instruction * llvm::InstCombinerImpl::foldSelectValueEquivalence ( SelectInst SI,
ICmpInst ICI 
)

◆ FoldShiftByConstant()

Instruction * InstCombinerImpl::FoldShiftByConstant ( Value Op0,
Constant Op1,
BinaryOperator I 
)

◆ foldSignBitTest()

Instruction * InstCombinerImpl::foldSignBitTest ( ICmpInst I)

◆ foldSPFofSPF()

Instruction * llvm::InstCombinerImpl::foldSPFofSPF ( Instruction Inner,
SelectPatternFlavor  SPF1,
Value A,
Value B,
Instruction Outer,
SelectPatternFlavor  SPF2,
Value C 
)

◆ foldSquareSumFP()

Instruction * InstCombinerImpl::foldSquareSumFP ( BinaryOperator I)

◆ foldSquareSumInt()

Instruction * InstCombinerImpl::foldSquareSumInt ( BinaryOperator I)

◆ foldUsingDistributiveLaws()

Value * InstCombinerImpl::foldUsingDistributiveLaws ( BinaryOperator I)

Tries to simplify binary operations which some other binary operation distributes over.

This tries to simplify binary operations which some other binary operation distributes over either by factorizing out common terms (eg "(A*B)+(A*C)" -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A & (B | C) -> (A&B) | (A&C)" if this is a win).

It does this by either by factorizing out common terms (eg "(A*B)+(A*C)" -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A & (B | C) -> (A&B) | (A&C)" if this is a win). Returns the simplified value, or null if it didn't simplify.

Returns the simplified value, or null if it didn't simplify.

Definition at line 1123 of file InstructionCombining.cpp.

References A, B, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateBinOp(), llvm::ConstantExpr::getBinOpIdentity(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::SimplifyQuery::getWithInstruction(), llvm::SimplifyQuery::getWithoutUndef(), I, leftDistributesOverRight(), LHS, RHS, rightDistributesOverLeft(), llvm::simplifyBinOp(), SimplifySelectsFeedingBinaryOp(), llvm::InstCombiner::SQ, and tryFactorizationFolds().

Referenced by visitAdd(), visitAnd(), visitMul(), visitOr(), visitSub(), and visitXor().

◆ foldVariableSignZeroExtensionOfVariableHighBitExtract()

Instruction * InstCombinerImpl::foldVariableSignZeroExtensionOfVariableHighBitExtract ( BinaryOperator OldAShr)

◆ foldVectorBinop()

Instruction * InstCombinerImpl::foldVectorBinop ( BinaryOperator Inst)

Canonicalize the position of binops relative to shufflevector.

Definition at line 2009 of file InstructionCombining.cpp.

References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::Instruction::copyIRFlags(), llvm::BinaryOperator::Create(), llvm::CallInst::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::InstCombiner::DL, F, llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::InstCombiner::getSafeVectorConstantForBinop(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::Value::hasNUses(), llvm::Value::hasOneUse(), I, llvm::is_contained(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), llvm::Instruction::isIntDivRem(), llvm::isSafeToSpeculativelyExecute(), llvm::Instruction::isShift(), llvm::isSplatValue(), LHS, llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VecReverse(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, RHS, llvm::ArrayRef< T >::size(), std::swap(), X, and Y.

Referenced by visitAdd(), visitAnd(), visitAShr(), visitFAdd(), visitFDiv(), visitFMul(), visitFRem(), visitFSub(), visitLShr(), visitMul(), visitOr(), visitSDiv(), visitShl(), visitSRem(), visitSub(), visitUDiv(), visitURem(), and visitXor().

◆ foldVectorSelect()

Instruction * llvm::InstCombinerImpl::foldVectorSelect ( SelectInst Sel)

◆ freelyInvertAllUsersOf()

void InstCombinerImpl::freelyInvertAllUsersOf ( Value I,
Value IgnoredUser = nullptr 
)

◆ freezeOtherUses()

bool InstCombinerImpl::freezeOtherUses ( FreezeInst FI)

◆ getLosslessSignedTrunc()

Constant * llvm::InstCombinerImpl::getLosslessSignedTrunc ( Constant C,
Type TruncTy 
)
inline

Definition at line 237 of file InstCombineInternal.h.

References C.

Referenced by foldLogicCastConstant(), and visitCallInst().

◆ getLosslessTrunc()

Constant * llvm::InstCombinerImpl::getLosslessTrunc ( Constant C,
Type TruncTy,
unsigned  ExtOp 
)
inline

Definition at line 224 of file InstCombineInternal.h.

References C, llvm::ConstantFoldCastOperand(), and DL.

Referenced by foldICmpWithZextOrSext().

◆ getLosslessUnsignedTrunc()

Constant * llvm::InstCombinerImpl::getLosslessUnsignedTrunc ( Constant C,
Type TruncTy 
)
inline

Definition at line 233 of file InstCombineInternal.h.

References C.

Referenced by foldLogicCastConstant(), foldPHIArgZextsIntoPHI(), narrowUDivURem(), and visitCallInst().

◆ handlePotentiallyDeadBlocks()

void InstCombinerImpl::handlePotentiallyDeadBlocks ( SmallVectorImpl< BasicBlock * > &  Worklist)

◆ handlePotentiallyDeadSuccessors()

void InstCombinerImpl::handlePotentiallyDeadSuccessors ( BasicBlock BB,
BasicBlock LiveSucc 
)

◆ handleUnreachableFrom()

void InstCombinerImpl::handleUnreachableFrom ( Instruction I,
SmallVectorImpl< BasicBlock * > &  Worklist 
)

◆ insertRangeTest()

Value * InstCombinerImpl::insertRangeTest ( Value V,
const APInt Lo,
const APInt Hi,
bool  isSigned,
bool  Inside 
)

Emit a computation of: (V >= Lo && V < Hi) if Inside is true, otherwise (V < Lo || V >= Hi).

This method expects that Lo < Hi. IsSigned indicates whether to treat V, Lo, and Hi as signed or not.

Definition at line 52 of file InstCombineAndOrXor.cpp.

References assert(), llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateSub(), llvm::ICmpInst::getSignedPredicate(), llvm::Hi, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, isSigned(), and llvm::Lo.

Referenced by foldICmpDivConstant().

◆ matchBSwapOrBitReverse()

Instruction * InstCombinerImpl::matchBSwapOrBitReverse ( Instruction I,
bool  MatchBSwaps,
bool  MatchBitReversals 
)

Given an initial instruction, check to see if it is the root of a bswap/bitreverse idiom.

If so, return the equivalent bswap/bitreverse intrinsic.

Definition at line 2786 of file InstCombineAndOrXor.cpp.

References I, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::InstructionWorklist::push(), llvm::recognizeBSwapOrBitReverseIdiom(), llvm::Instruction::removeFromParent(), and llvm::InstCombiner::Worklist.

Referenced by visitCallInst(), and visitOr().

◆ matchThreeWayIntCompare()

bool InstCombinerImpl::matchThreeWayIntCompare ( SelectInst SI,
Value *&  LHS,
Value *&  RHS,
ConstantInt *&  Less,
ConstantInt *&  Equal,
ConstantInt *&  Greater 
)

Match a select chain which produces one of three values based on whether the LHS is less than, equal to, or greater than RHS respectively.

Return true if we matched a three way compare idiom. The LHS, RHS, Less, Equal and Greater values are saved in the matching process and returned to the caller.

Definition at line 3130 of file InstCombineCompares.cpp.

References assert(), llvm::InstCombiner::getFlippedStrictnessPredicateAndConstant(), llvm::CmpInst::getSwappedPredicate(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::ICmpInst::isEquality(), llvm::Less, LHS, llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), RHS, and std::swap().

Referenced by foldICmpSelectConstant().

◆ mergeStoreIntoSuccessor()

bool InstCombinerImpl::mergeStoreIntoSuccessor ( StoreInst SI)

◆ OptimizePointerDifference()

Value * InstCombinerImpl::OptimizePointerDifference ( Value LHS,
Value RHS,
Type Ty,
bool  IsNUW 
)

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 1974 of file InstCombineAddSub.cpp.

References llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateIntCast(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateSub(), I, llvm::GEPOperator::isInBounds(), LHS, llvm::Offset, RHS, llvm::Value::stripPointerCasts(), and std::swap().

Referenced by visitSub().

◆ PHIArgMergedDebugLoc()

void InstCombinerImpl::PHIArgMergedDebugLoc ( Instruction Inst,
PHINode PN 
)

Helper function for FoldPHIArgXIntoPHI() to set debug location for the folded operation.

The PHI arguments will be folded into a single operation with a PHI node as input.

The debug location of the single operation will be the merged locations of the original PHI node arguments.

Definition at line 43 of file InstCombinePHI.cpp.

References llvm::Instruction::applyMergedLocation(), assert(), llvm::drop_begin(), llvm::Instruction::getDebugLoc(), llvm::PHINode::getIncomingValue(), I, llvm::PHINode::incoming_values(), and llvm::Instruction::setDebugLoc().

Referenced by foldPHIArgBinOpIntoPHI(), foldPHIArgExtractValueInstructionIntoPHI(), foldPHIArgGEPIntoPHI(), foldPHIArgInsertValueInstructionIntoPHI(), foldPHIArgLoadIntoPHI(), and foldPHIArgOpIntoPHI().

◆ prepareWorklist()

bool InstCombinerImpl::prepareWorklist ( Function F,
ReversePostOrderTraversal< BasicBlock * > &  RPOT 
)

Perform early cleanup and prepare the InstCombine worklist.

Populate the IC worklist from a function, by walking it in reverse post-order and adding all reachable code to the worklist.

This has a couple of tricks to make the code faster and more powerful. In particular, we constant fold and DCE instructions as we go, to avoid adding them to the worklist (this significantly speeds up instcombine on code where many instructions are dead or constant). Additionally, if we find a branch whose condition is a known constant, we only visit the reachable successors.

Definition at line 5202 of file InstructionCombining.cpp.

References llvm::all_of(), AliasScopeTracker::analyse(), llvm::CallingConv::C, Cond, llvm::ConstantFoldConstant(), llvm::ConstantFoldInstruction(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::InstCombiner::DeadEdges, llvm::InstCombiner::DL, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, F, llvm::PoisonValue::get(), llvm::BasicBlock::getTerminator(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::BranchInst::isConditional(), llvm::BasicBlock::isEntryBlock(), llvm::isInstructionTriviallyDead(), AliasScopeTracker::isNoAliasScopeDeclDead(), LLVM_DEBUG, llvm::InstCombiner::MadeIRChange, llvm::make_early_inc_range(), llvm::predecessors(), llvm::InstructionWorklist::push(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::removeAllNonTerminatorAndEHPadInstructions(), llvm::InstructionWorklist::reserve(), llvm::reverse(), llvm::salvageDebugInfo(), llvm::SmallVectorBase< Size_T >::size(), llvm::successors(), llvm::InstCombiner::TLI, and llvm::InstCombiner::Worklist.

Referenced by combineInstructionsOverFunction().

◆ pushFreezeToPreventPoisonFromPropagating()

Value * InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating ( FreezeInst FI)

◆ reassociateShiftAmtsOfTwoSameDirectionShifts()

Value * InstCombinerImpl::reassociateShiftAmtsOfTwoSameDirectionShifts ( BinaryOperator Sh0,
const SimplifyQuery SQ,
bool  AnalyzeForSignBitExtraction = false 
)

◆ removeInstructionsBeforeUnreachable()

bool InstCombinerImpl::removeInstructionsBeforeUnreachable ( Instruction I)

◆ replacedSelectWithOperand()

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

Try to replace select with select operand SIOpd in SI-ICmp sequence.

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 6290 of file InstCombineCompares.cpp.

References assert(), dominatesAllUses(), llvm::CmpInst::getPredicate(), llvm::BasicBlock::getSinglePredecessor(), llvm::CmpInst::ICMP_EQ, and isChainSelectCmpBranch().

Referenced by foldSelectICmp().

◆ replaceInInstruction()

bool llvm::InstCombinerImpl::replaceInInstruction ( Value V,
Value Old,
Value New,
unsigned  Depth = 0 
)

◆ run()

bool InstCombinerImpl::run ( )

◆ SimplifyAddWithRemainder()

Value * InstCombinerImpl::SimplifyAddWithRemainder ( BinaryOperator I)

Tries to simplify add operations using the definition of remainder.

The definition of remainder is X % C = X - (X / C ) * C. The add expression X % C0 + (( X / C0 ) % C1) * C0 can be simplified to X % (C0 * C1)

Definition at line 1139 of file InstCombineAddSub.cpp.

References llvm::InstCombiner::AC, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateMul(), llvm::IRBuilderBase::CreateSRem(), llvm::IRBuilderBase::CreateURem(), llvm::InstCombiner::DT, llvm::Value::hasOneUse(), I, llvm::isGuaranteedNotToBeUndef(), llvm::APInt::isZero(), LHS, llvm::PatternMatch::m_IRem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), MatchDiv(), MatchMul(), MatchRem(), MulWillOverflow(), RHS, std::swap(), and X.

Referenced by visitAdd(), and visitOr().

◆ SimplifyAnyMemSet()

Instruction * InstCombinerImpl::SimplifyAnyMemSet ( AnyMemSetInst MI)

◆ SimplifyAnyMemTransfer()

Instruction * InstCombinerImpl::SimplifyAnyMemTransfer ( AnyMemTransferInst MI)

◆ SimplifyAssociativeOrCommutative()

bool InstCombinerImpl::SimplifyAssociativeOrCommutative ( BinaryOperator I)

Performs a few simplifications for operators which are associative or commutative.

This performs a few simplifications for operators that are associative or commutative:

Commutative operators:

  1. Order operands such that they are listed from right (least complex) to left (most complex). This puts constants before unary operators before binary operators.

Associative operators:

  1. Transform: "(A op B) op C" ==> "A op (B op C)" if "B op C" simplifies.
  2. Transform: "A op (B op C)" ==> "(A op B) op C" if "A op B" simplifies.

Associative and commutative operators:

  1. Transform: "(A op B) op C" ==> "(C op A) op B" if "C op A" simplifies.
  2. Transform: "A op (B op C)" ==> "B op (C op A)" if "C op A" simplifies.
  3. Transform: "(A op C1) op (B op C2)" ==> "(A op B) op (C1 op C2)" if C1 and C2 are constants.

Definition at line 420 of file InstructionCombining.cpp.

References A, B, llvm::CallingConv::C, ClearSubclassDataAfterReassociation(), llvm::ConstantFoldBinaryOpOperands(), llvm::BinaryOperator::Create(), llvm::BinaryOperator::CreateNUW(), llvm::InstCombiner::DL, llvm::InstCombiner::getComplexity(), llvm::Instruction::getFastMathFlags(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::SimplifyQuery::getWithInstruction(), hasNoSignedWrap(), hasNoUnsignedWrap(), I, llvm::InstCombiner::InsertNewInstWith(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), maintainNoSignedWrap(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), llvm::Instruction::setFastMathFlags(), simplifyAssocCastAssoc(), llvm::simplifyBinOp(), llvm::InstCombiner::SQ, and llvm::Value::takeName().

Referenced by visitAdd(), visitAnd(), visitFAdd(), visitFMul(), visitMul(), visitOr(), and visitXor().

◆ simplifyBinOpSplats()

Instruction * InstCombinerImpl::simplifyBinOpSplats ( ShuffleVectorInst SVI)

◆ SimplifyDemandedBits()

bool InstCombinerImpl::SimplifyDemandedBits ( Instruction I,
unsigned  OpNo,
const APInt DemandedMask,
KnownBits Known,
unsigned  Depth = 0 
)
overridevirtual

This form of SimplifyDemandedBits simplifies the specified instruction operand if possible, updating it in place.

It returns true if it made any change and false otherwise.

Implements llvm::InstCombiner.

Definition at line 89 of file InstCombineSimplifyDemanded.cpp.

References llvm::Depth, I, llvm::InstCombiner::replaceUse(), llvm::salvageDebugInfo(), and SimplifyDemandedUseBits().

Referenced by foldICmpUsingKnownBits(), SimplifyDemandedUseBits(), and visitCallInst().

◆ SimplifyDemandedFPClass()

bool InstCombinerImpl::SimplifyDemandedFPClass ( Instruction I,
unsigned  Op,
FPClassTest  DemandedMask,
KnownFPClass Known,
unsigned  Depth = 0 
)

◆ SimplifyDemandedInstructionBits() [1/2]

bool InstCombinerImpl::SimplifyDemandedInstructionBits ( Instruction Inst)

Tries to simplify operands to an integer instruction based on its demanded bits.

Inst is an integer instruction that SimplifyDemandedBits knows about.

See if the instruction has any properties that allow us to simplify its operands.

Definition at line 81 of file InstCombineSimplifyDemanded.cpp.

References llvm::InstCombiner::DL, getBitWidth(), llvm::Value::getType(), and SimplifyDemandedInstructionBits().

Referenced by commonIDivTransforms(), commonIRemTransforms(), commonShiftTransforms(), SimplifyDemandedInstructionBits(), visitAnd(), visitCallInst(), visitOr(), visitTrunc(), and visitXor().

◆ SimplifyDemandedInstructionBits() [2/2]

bool InstCombinerImpl::SimplifyDemandedInstructionBits ( Instruction Inst,
KnownBits Known 
)

Inst is an integer instruction that SimplifyDemandedBits knows about.

See if the instruction has any properties that allow us to simplify its operands.

Definition at line 68 of file InstCombineSimplifyDemanded.cpp.

References llvm::APInt::getAllOnes(), llvm::KnownBits::getBitWidth(), llvm::InstCombiner::replaceInstUsesWith(), and SimplifyDemandedUseBits().

◆ SimplifyDemandedUseBits()

Value * InstCombinerImpl::SimplifyDemandedUseBits ( Value V,
APInt  DemandedMask,
KnownBits Known,
unsigned  Depth,
Instruction CxtI 
)

Attempts to replace V with a simpler value based on the demanded bits.

This function attempts to replace V with a simpler value based on the demanded bits.

When this function is called, it is known that only the bits set in DemandedMask of the result of V are ever used downstream. Consequently, depending on the mask and V, it may be possible to replace V with a constant or one of its operands. In such cases, this function does the replacement and returns true. In all other cases, it returns false after analyzing the expression and setting KnownOne and known to be one in the expression. Known.Zero contains all the bits that are known to be zero in the expression. These are provided to potentially allow the caller (which might recursively be SimplifyDemandedBits itself) to simplify the expression. Known.One and Known.Zero always follow the invariant that: Known.One & Known.Zero == 0. That is, a bit can't be both 1 and 0. The bits in Known.One and Known.Zero are accurate even for bits not in DemandedMask. Note also that the bitwidth of V, DemandedMask, Known.Zero and Known.One must all be the same.

This returns null if it did not change anything and it permits no simplification. This returns V itself if it did some simplification of V's operands based on the information about what bits are demanded. This returns some other non-null value if it found out that V is equal to another value in the context where the specified bits are demanded, but not for all users.

Definition at line 126 of file InstCombineSimplifyDemanded.cpp.

References llvm::APInt::abs(), llvm::alignDown(), llvm::AllOnes, llvm::analyzeKnownBitsFromAndXorOr(), llvm::And, llvm::KnownBits::anyextOrTrunc(), assert(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APInt::clearLowBits(), llvm::KnownBits::computeForAddSub(), llvm::InstCombiner::computeKnownBits(), llvm::InstCombiner::ComputeNumSignBits(), llvm::ConstantFoldBinaryOpOperands(), convertOrOfShiftsToFunnelShift(), llvm::APInt::countl_zero(), llvm::countr_one(), llvm::APInt::countr_zero(), llvm::CallInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateGEP(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateSExt(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::IRBuilderBase::CreateXor(), llvm::Depth, llvm::InstCombiner::DL, llvm::errs(), GEP, llvm::UndefValue::get(), llvm::APInt::getActiveBits(), llvm::APInt::getAllOnes(), llvm::Constant::getAllOnesValue(), llvm::APInt::getBitWidth(), llvm::KnownBits::getBitWidth(), llvm::Intrinsic::getDeclaration(), llvm::APInt::getHighBitsSet(), llvm::DataLayout::getIndexType(), llvm::Constant::getIntegerValue(), llvm::APInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignMask(), llvm::ConstantInt::getValue(), llvm::SimplifyQuery::getWithInstruction(), llvm::KnownBits::hasConflict(), llvm::OverflowingBinaryOperator::hasNoSignedWrap(), llvm::OverflowingBinaryOperator::hasNoUnsignedWrap(), llvm::haveNoCommonBitsSet(), I, llvm::InstCombiner::InsertNewInstWith(), llvm::APInt::intersects(), llvm::KnownBits::intersectWith(), llvm::APInt::isAllOnes(), llvm::Type::isIntOrIntVectorTy(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm::APInt::isOne(), llvm::APInt::isPowerOf2(), llvm::APInt::isSubsetOf(), llvm::APInt::isZero(), LHS, llvm::Log2(), llvm::APInt::lshr(), llvm::APInt::lshrInPlace(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PtrAdd(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::KnownBits::makeConstant(), llvm::KnownBits::makeNonNegative(), llvm::PatternMatch::match(), llvm::MaxAnalysisRecursionDepth, llvm::KnownBits::One, llvm::Or, RA, llvm::InstCombiner::replaceOperand(), llvm::KnownBits::resetAll(), RHS, llvm::APInt::setAllBits(), llvm::APInt::setBit(), llvm::APInt::setHighBits(), llvm::IRBuilderBase::SetInsertPoint(), llvm::Instruction::setIsExact(), llvm::APInt::setLowBits(), llvm::APInt::setSignBit(), llvm::KnownBits::sext(), llvm::KnownBits::shl(), llvm::APInt::shl(), ShrinkDemandedConstant(), SimplifyDemandedBits(), SimplifyMultipleUseDemandedBits(), simplifyShrShlDemandedBits(), llvm::InstCombiner::SQ, llvm::Value::takeName(), llvm::InstCombiner::targetSimplifyDemandedUseBitsIntrinsic(), llvm::APInt::trunc(), llvm::KnownBits::udiv(), llvm::APInt::ult(), llvm::APInt::urem(), llvm::KnownBits::urem(), VerifyKnownBits, X, llvm::Xor, Y, llvm::KnownBits::Zero, llvm::KnownBits::zextOrTrunc(), and llvm::APInt::zextOrTrunc().

Referenced by SimplifyDemandedBits(), and SimplifyDemandedInstructionBits().

◆ SimplifyDemandedUseFPClass()

Value * InstCombinerImpl::SimplifyDemandedUseFPClass ( Value V,
FPClassTest  DemandedMask,
KnownFPClass Known,
unsigned  Depth,
Instruction CxtI 
)

◆ SimplifyDemandedVectorElts()

Value * InstCombinerImpl::SimplifyDemandedVectorElts ( Value V,
APInt  DemandedElts,
APInt PoisonElts,
unsigned  Depth = 0,
bool  AllowMultipleUsers = false 
)
overridevirtual

The specified value produces a vector with any number of elements.

This method analyzes which elements of the operand are poison and returns that information in PoisonElts.

DemandedElts contains the set of elements that are actually used by the caller, and by default (AllowMultipleUsers equals false) the value is simplified only if it has a single caller. If AllowMultipleUsers is set to true, DemandedElts refers to the union of sets of elements that are used by all callers.

If the information about demanded elements can be used to simplify the operation, the operation is simplified, then the resultant value is returned. This returns null if no change was made.

Implements llvm::InstCombiner.

Definition at line 1415 of file InstCombineSimplifyDemanded.cpp.

References llvm::all_of(), assert(), llvm::CallingConv::C, llvm::APInt::clearAllBits(), llvm::APInt::clearBit(), llvm::InsertElementInst::Create(), llvm::Depth, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, GEP, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::APInt::getAllOnes(), llvm::SelectInst::getCondition(), llvm::Type::getInt64Ty(), llvm::IntrinsicInst::getIntrinsicID(), llvm::Value::getName(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, Idx, llvm::InstCombiner::InsertNewInstWith(), llvm::APInt::isAllOnes(), llvm::Constant::isAllOnesValue(), llvm::Instruction::isCommutative(), llvm::Instruction::isIntDivRem(), llvm::Constant::isNullValue(), llvm::Instruction::isShift(), llvm::Type::isVectorTy(), llvm::APInt::isZero(), llvm_unreachable, llvm::APInt::lshr(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_ExtractElt(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, llvm::APInt::popcount(), llvm::InstructionWorklist::push(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceOperand(), llvm::APInt::setBit(), SimplifyDemandedVectorElts(), llvm::InstCombiner::targetSimplifyDemandedVectorEltsIntrinsic(), llvm::Value::users(), llvm::InstCombiner::Worklist, X, Y, and llvm::APInt::zextOrTrunc().

Referenced by SimplifyDemandedVectorElts(), visitCallInst(), visitExtractElementInst(), visitGetElementPtrInst(), visitInsertElementInst(), and visitShuffleVectorInst().

◆ simplifyDivRemOfSelectWithZeroOp()

bool InstCombinerImpl::simplifyDivRemOfSelectWithZeroOp ( BinaryOperator I)

Fold a divide or remainder with a select instruction divisor when one of the select operands is zero.

In that case, we can use the other select operand because div/rem by zero is undefined.

Definition at line 937 of file InstCombineMulDivRem.cpp.

References llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::isGuaranteedToTransferExecutionToSuccessor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::InstructionWorklist::push(), llvm::InstCombiner::replaceOperand(), llvm::InstCombiner::replaceUse(), and llvm::InstCombiner::Worklist.

Referenced by commonIDivTransforms(), and commonIRemTransforms().

◆ SimplifyMultipleUseDemandedBits()

Value * InstCombinerImpl::SimplifyMultipleUseDemandedBits ( Instruction I,
const APInt DemandedMask,
KnownBits Known,
unsigned  Depth,
Instruction CxtI 
)

◆ simplifyRangeCheck()

Value * InstCombinerImpl::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 653 of file InstCombineAndOrXor.cpp.

References llvm::InstCombiner::Builder, llvm::InstCombiner::computeKnownBits(), llvm::IRBuilderBase::CreateICmp(), 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(), llvm::KnownBits::isNonNegative(), and llvm::ConstantInt::isZero().

◆ SimplifySelectsFeedingBinaryOp()

Value * InstCombinerImpl::SimplifySelectsFeedingBinaryOp ( BinaryOperator I,
Value LHS,
Value RHS 
)

◆ simplifyShrShlDemandedBits()

Value * InstCombinerImpl::simplifyShrShlDemandedBits ( Instruction Shr,
const APInt ShrOp1,
Instruction Shl,
const APInt ShlOp1,
const APInt DemandedMask,
KnownBits Known 
)

Helper routine of SimplifyDemandedUseBits.

It tries to simplify demanded bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.

It tries to simplify "E1 = (X lsr C1) << C2", where the C1 and C2 are constant, into "E2 = X << (C2 - C1)" or "E2 = X >> (C1 - C2)", depending on the sign of "C2-C1".

Suppose E1 and E2 are generally different in bits S={bm, bm+1, ..., bn}, without considering the specific value X is holding. This transformation is legal iff one of following conditions is hold: 1) All the bit in S are 0, in this case E1 == E2. 2) We don't care those bits in S, per the input DemandedMask. 3) Combination of 1) and 2). Some bits in S are 0, and we don't care the rest bits.

Currently we only test condition 2).

As with SimplifyDemandedUseBits, it returns NULL if the simplification was not successful.

Definition at line 1340 of file InstCombineSimplifyDemanded.cpp.

References llvm::APInt::ashr(), llvm::BitWidth, llvm::APInt::clearAllBits(), llvm::APInt::getAllOnes(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::APInt::getZExtValue(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::InstCombiner::InsertNewInstWith(), llvm::APInt::lshr(), llvm::KnownBits::One, llvm::APInt::setLowBits(), llvm::APInt::uge(), and llvm::KnownBits::Zero.

Referenced by SimplifyDemandedUseBits().

◆ sinkNotIntoLogicalOp()

bool InstCombinerImpl::sinkNotIntoLogicalOp ( Instruction I)

◆ sinkNotIntoOtherHandOfLogicalOp()

bool InstCombinerImpl::sinkNotIntoOtherHandOfLogicalOp ( Instruction I)

◆ SliceUpIllegalIntegerPHI()

Instruction * InstCombinerImpl::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 1098 of file InstCombinePHI.cpp.

References llvm::PHINode::addIncoming(), llvm::array_pod_sort(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::PHINode::blocks(), llvm::InstCombiner::Builder, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::PHINode::Create(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateTrunc(), llvm::dbgs(), llvm::drop_begin(), llvm::SmallVectorBase< Size_T >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::find(), llvm::PoisonValue::get(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Type::getScalarSizeInBits(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::PHINode::incoming_values(), llvm::SmallPtrSetImpl< PtrType >::insert(), LLVM_DEBUG, llvm::Offset, PHI, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallVectorBase< Size_T >::size(), llvm::Instruction::user_back(), llvm::Value::users(), and llvm::zip().

◆ tryFactorizationFolds()

Value * InstCombinerImpl::tryFactorizationFolds ( BinaryOperator I)

This tries to simplify binary operations by factorizing out common terms (e.

g. "(A*B)+(A*C)" -> "A*(B+C)").

Definition at line 1080 of file InstructionCombining.cpp.

References A, B, llvm::InstCombiner::Builder, llvm::CallingConv::C, D, getBinOpsForFactorization(), getIdentityValue(), I, LHS, RHS, llvm::InstCombiner::SQ, and tryFactorization().

Referenced by foldUsingDistributiveLaws().

◆ tryFoldInstWithCtpopWithNot()

Instruction * InstCombinerImpl::tryFoldInstWithCtpopWithNot ( Instruction I)

◆ tryToSinkInstruction()

bool InstCombinerImpl::tryToSinkInstruction ( Instruction I,
BasicBlock DestBlock 
)

Try to move the specified instruction from its current block into the beginning of DestBlock, which can only happen if it's safe to move the instruction past all of the instructions between it and the end of its block.

FIXME: We could remove droppable uses that are not dominated by the new position.

Definition at line 4684 of file InstructionCombining.cpp.

References llvm::InstructionWorklist::add(), llvm::SmallVectorBase< Size_T >::empty(), llvm::findDbgUsers(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::getUniquePredecessor(), I, SoleWriteToDeadLocal(), llvm::InstCombiner::TLI, tryToSinkInstructionDbgValues(), tryToSinkInstructionDbgVariableRecords(), and llvm::InstCombiner::Worklist.

Referenced by run().

◆ tryToSinkInstructionDbgValues()

void InstCombinerImpl::tryToSinkInstructionDbgValues ( Instruction I,
BasicBlock::iterator  InsertPos,
BasicBlock SrcBlock,
BasicBlock DestBlock,
SmallVectorImpl< DbgVariableIntrinsic * > &  DbgUsers 
)

◆ tryToSinkInstructionDbgVariableRecords()

void InstCombinerImpl::tryToSinkInstructionDbgVariableRecords ( Instruction I,
BasicBlock::iterator  InsertPos,
BasicBlock SrcBlock,
BasicBlock DestBlock,
SmallVectorImpl< DbgVariableRecord * > &  DPUsers 
)

◆ visitAdd()

Instruction * InstCombinerImpl::visitAdd ( BinaryOperator I)

Definition at line 1475 of file InstCombineAddSub.cpp.

References A, llvm::Add, llvm::AllOnes, assert(), B, llvm::BitWidth, llvm::InstCombiner::Builder, canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(), canonicalizeLowbitMask(), checkForNegativeOperand(), combineAddSubWithShlAddSub(), llvm::InstCombiner::ComputeNumSignBits(), llvm::APInt::countl_zero(), llvm::APInt::countr_zero(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateMul(), llvm::BinaryOperator::CreateNeg(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateXor(), llvm::IRBuilderBase::CreateZExt(), llvm::IRBuilderBase::CreateZExtOrTrunc(), factorizeMathWithShlOps(), foldAddToAshr(), foldAddWithConstant(), foldBinOpOfSelectAndCastOfSelectCondition(), foldBinOpShiftWithShift(), foldBinopWithPhiOperands(), foldBoxMultiply(), foldNoWrapAdd(), foldSquareSumInt(), foldToUnsignedSaturatedAdd(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::ConstantExpr::getAdd(), llvm::Constant::getAllOnesValue(), llvm::APInt::getBitWidth(), llvm::IRBuilderBase::getFalse(), llvm::InstCombiner::getFreelyInverted(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::ConstantInt::getSigned(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), llvm::haveNoCommonBitsSet(), I, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_UGT, llvm::InstCombiner::isFreeToInvert(), llvm::Type::isIntOrIntVectorTy(), llvm::APInt::isPowerOf2(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NegatedPower2(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_TruncOrSelf(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSelf(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), RHS, llvm::simplifyAddInst(), SimplifyAddWithRemainder(), SimplifyAssociativeOrCommutative(), llvm::InstCombiner::SQ, tryFoldInstWithCtpopWithNot(), and X.

◆ visitAddrSpaceCast()

Instruction * InstCombinerImpl::visitAddrSpaceCast ( AddrSpaceCastInst CI)

Definition at line 2816 of file InstCombineCasts.cpp.

References commonCastTransforms().

◆ visitAllocaInst()

Instruction * InstCombinerImpl::visitAllocaInst ( AllocaInst AI)

◆ visitAllocSite()

Instruction * InstCombinerImpl::visitAllocSite ( Instruction FI)

◆ visitAnd()

Instruction * InstCombinerImpl::visitAnd ( BinaryOperator I)

Definition at line 2262 of file InstCombineAndOrXor.cpp.

References A, llvm::And, assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeLogicFirst(), llvm::InstCombiner::computeKnownBits(), llvm::ConstantFoldCompareInstOperands(), llvm::APInt::countr_zero(), llvm::BinaryOperator::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateIsNeg(), llvm::IRBuilderBase::CreateIsNull(), llvm::IRBuilderBase::CreateLogicalAnd(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateSExt(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::InstCombiner::DL, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::APInt::exactLogBase2(), foldAndToXor(), foldBinOpIntoSelectOrPhi(), foldBinOpShiftWithShift(), foldBinopWithPhiOperands(), foldBitwiseLogicWithIntrinsics(), foldComplexAndOrPatterns(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::ConstantExpr::getAdd(), llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getExactLogBase2(), llvm::InstCombiner::getFreelyInverted(), llvm::IRBuilderBase::GetInsertBlock(), llvm::APInt::getLowBitsSet(), llvm::KnownBits::getMaxValue(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::BasicBlock::getParent(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::APInt::getZExtValue(), llvm::Function::hasFnAttribute(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_ULT, llvm::Type::isFloatingPointTy(), llvm::Type::isIEEE(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::APInt::isPowerOf2(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalShift(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_MaxSignedValue(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_SExtOrSelf(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSelf(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), matchDeMorgansLaws(), llvm::matchSimpleRecurrence(), reassociateFCmps(), reassociateForUses(), llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::simplifyAndInst(), simplifyAndOrWithOpReplaced(), SimplifyAssociativeOrCommutative(), SimplifyDemandedInstructionBits(), sinkNotIntoOtherHandOfLogicalOp(), llvm::InstCombiner::SQ, llvm::APInt::trunc(), llvm::APInt::ult(), X, llvm::Xor, Y, and llvm::APInt::zext().

◆ visitAShr()

Instruction * InstCombinerImpl::visitAShr ( BinaryOperator I)

◆ visitAtomicRMWInst()

Instruction * InstCombinerImpl::visitAtomicRMWInst ( AtomicRMWInst SI)

◆ visitBitCast()

Instruction * InstCombinerImpl::visitBitCast ( BitCastInst CI)

◆ visitBranchInst()

Instruction * InstCombinerImpl::visitBranchInst ( BranchInst BI)

◆ visitCallBrInst()

Instruction * InstCombinerImpl::visitCallBrInst ( CallBrInst CBI)

Definition at line 3551 of file InstCombineCalls.cpp.

◆ visitCallInst()

Instruction * InstCombinerImpl::visitCallInst ( CallInst CI)

CallInst simplification.

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

This will remove the boolean Condition from the assume given as argument and remove the assume if it becomes useless. always returns nullptr for use as a return values.

Note: this doesn't preserve the offset information but merges offset and alignment. TODO: we can generate a GEP instead of merging the alignment with the offset.

Canonicalize Knowledge in operand bundles.

Definition at line 1468 of file InstCombineCalls.cpp.

References A, llvm::InstCombiner::AA, llvm::InstCombiner::AC, llvm::InstructionWorklist::add(), llvm::CallBase::addRetAttr(), llvm::alignDown(), llvm::FastMathFlags::allowReassoc(), llvm::AlwaysOverflowsHigh, llvm::AlwaysOverflowsLow, llvm::Instruction::andIRFlags(), llvm::CallBase::arg_size(), llvm::CallBase::args(), llvm::RetainedKnowledge::ArgValue, assert(), llvm::RetainedKnowledge::AttrKind, B, llvm::BitWidth, llvm::buildAssumeFromKnowledge(), llvm::InstCombiner::Builder, llvm::CallBase::bundle_op_info_begin(), llvm::CallingConv::C, canonicalizeConstantArg0ToArg1(), llvm::APFloat::clearSign(), llvm::computeConstantRangeIncludingKnownBits(), llvm::InstCombiner::computeKnownBits(), llvm::computeKnownFPSignBit(), computeOverflow(), Cond, llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldCompareInstOperands(), llvm::Instruction::copyFastMathFlags(), llvm::Instruction::copyIRFlags(), llvm::KnownBits::countMinLeadingZeros(), llvm::KnownBits::countMinTrailingZeros(), llvm::BinaryOperator::Create(), llvm::CallInst::Create(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAddReduce(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateAndReduce(), llvm::IRBuilderBase::CreateBinaryIntrinsic(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateCast(), llvm::BinaryOperator::CreateFDivFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::IRBuilderBase::CreateFNeg(), llvm::IRBuilderBase::CreateFNegFMF(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpNE(), llvm::IRBuilderBase::CreateIntCast(), llvm::CastInst::CreateIntegerCast(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateMul(), llvm::BinaryOperator::CreateNeg(), llvm::IRBuilderBase::CreateNeg(), CreateNonTerminatorUnreachable(), llvm::BinaryOperator::CreateNot(), llvm::IRBuilderBase::CreateNot(), llvm::BinaryOperator::CreateNSW(), llvm::IRBuilderBase::CreateNSWMul(), llvm::BinaryOperator::CreateNSWNeg(), llvm::BinaryOperator::CreateNUW(), llvm::IRBuilderBase::CreateOrReduce(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::BinaryOperator::CreateWithCopiedFlags(), llvm::UnaryOperator::CreateWithCopiedFlags(), llvm::IRBuilderBase::CreateZExt(), llvm::IRBuilderBase::CreateZExtOrTrunc(), llvm::Data, llvm::InstCombiner::DL, llvm::Function::doesNotThrow(), llvm::CallBase::doesNotThrow(), llvm::Value::dropDroppableUse(), llvm::InstCombiner::DT, llvm::EnableKnowledgeRetention, eraseInstFromFunction(), factorizeMinMaxTree(), llvm::FAdd, foldClampRangeOfTwo(), foldCtpop(), foldCttzCtlz(), FoldOpIntoSelect(), foldShuffledIntrinsicOperands(), llvm::MDNode::get(), llvm::ConstantAggregateZero::get(), llvm::APInt::getAllOnes(), llvm::Constant::getAllOnesValue(), llvm::CallBase::getArgOperand(), llvm::InstCombiner::getAssumptionCache(), llvm::KnownBits::getBitWidth(), llvm::ConstantInt::getBool(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCalledOperand(), llvm::Value::getContext(), llvm::Intrinsic::getDeclaration(), llvm::InstCombiner::getDominatorTree(), llvm::VectorType::getElementCount(), llvm::IRBuilderBase::getFalse(), llvm::Instruction::getFastMathFlags(), llvm::getFreedOperand(), llvm::InstCombiner::getFreelyInverted(), llvm::Instruction::getFunction(), llvm::CallBase::getFunctionType(), llvm::IRBuilderBase::getInt1Ty(), llvm::Type::getInt64Ty(), llvm::Constant::getIntegerValue(), llvm::IRBuilderBase::getIntNTy(), llvm::CallBase::getIntrinsicID(), llvm::IntrinsicInst::getIntrinsicID(), llvm::getInverseMinMaxIntrinsic(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::getKnowledgeFromBundle(), llvm::getKnownAlignment(), getKnownSign(), getKnownSignOrZero(), getLosslessSignedTrunc(), getLosslessUnsignedTrunc(), llvm::APInt::getLowBitsSet(), llvm::APSInt::getMaxValue(), llvm::APSInt::getMinValue(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::ConstantExpr::getNeg(), llvm::Instruction::getNextNonDebugInstruction(), llvm::CmpInst::getNonStrictPredicate(), llvm::Constant::getNullValue(), llvm::CallBase::getNumOperandBundles(), llvm::Instruction::getOpcode(), getOpcode(), llvm::User::getOperand(), llvm::CallBase::getOperandBundleAt(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::User::getOperandUse(), llvm::Instruction::getParent(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::MinMaxIntrinsic::getPredicate(), llvm::CallBase::getRetAlign(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignedMinValue(), llvm::APInt::getSignMask(), llvm::InstCombiner::getSimplifyQuery(), llvm::ConstantExpr::getSub(), llvm::CmpInst::getSwappedPredicate(), llvm::OperandBundleUse::getTagName(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::getUnderlyingObject(), llvm::Attribute::getWithAlignment(), llvm::SimplifyQuery::getWithInstruction(), GuardWideningWindow, llvm::Instruction::hasAllowReassoc(), llvm::Function::hasFnAttribute(), llvm::Value::hasOneUse(), llvm::CallBase::hasOperandBundles(), llvm::CallBase::hasRetAttr(), I, llvm::ConstantRange::icmp(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, Idx, llvm::OperandBundleUse::Inputs, llvm::KnownBits::isAllOnes(), llvm::isAssumeWithEmptyBundle(), llvm::IntrinsicInst::isCommutative(), llvm::InstCombiner::isFreeToInvert(), llvm::ConstantRange::isFullSet(), llvm::Type::isIntOrIntVectorTy(), llvm::details::FixedOrScalableQuantity< ElementCount, unsigned >::isKnownGT(), llvm::details::FixedOrScalableQuantity< ElementCount, unsigned >::isKnownLT(), llvm::isKnownNegation(), llvm::isKnownNonZero(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::APFloat::isNegative(), llvm::APInt::isNonNegative(), llvm::KnownBits::isNonZero(), llvm::Type::isPointerTy(), llvm::isPowerOf2_32(), llvm::isPowerOf2_64(), llvm::isSafeToSpeculativelyExecute(), llvm::MinMaxIntrinsic::isSigned(), llvm::isSplatValue(), llvm::isValidAssumeForContext(), LHS, llvm_unreachable, llvm::Log2(), llvm::Log2_32_Ceil(), llvm::lowerObjectSizeCall(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_BSwap(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_Cmp(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_CopySign(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_FAbs(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_LogicalShift(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NegatedPower2(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWAddLike(), llvm::PatternMatch::m_NSWNeg(), llvm::PatternMatch::m_NUWAddLike(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_UnOp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VecReverse(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExtOrSelf(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), matchBSwapOrBitReverse(), llvm::Value::MaxAlignmentExponent, llvm::maximum(), llvm::maxnum(), llvm::Instruction::mayHaveSideEffects(), llvm::MayOverflow, MI, llvm::MinAlign(), llvm::minimum(), llvm::minnum(), llvm::Mod, moveAddAfterMinMax(), llvm::Instruction::moveBefore(), llvm::NeverOverflows, llvm::None, llvm::FastMathFlags::noSignedZeros(), llvm::Offset, llvm::User::op_begin(), llvm::Other, llvm::PoisonMaskElem, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstructionWorklist::pushValue(), reassociateMinMaxWithConstantInOperand(), reassociateMinMaxWithConstants(), llvm::AssumptionCache::registerAssumption(), removeTriviallyEmptyRange(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::InstCombiner::replaceUse(), RetTy, llvm::APInt::sadd_ov(), llvm::Use::set(), llvm::CallBase::setArgOperand(), llvm::CallBase::setCalledFunction(), llvm::CallBase::setDoesNotThrow(), llvm::Instruction::setFastMathFlags(), llvm::Value::setMetadata(), llvm::FastMathFlags::setNoSignedZeros(), signBitMustBeTheSame(), SimplifyAnyMemSet(), SimplifyAnyMemTransfer(), llvm::simplifyCall(), llvm::simplifyConstrainedFPCall(), SimplifyDemandedBits(), SimplifyDemandedInstructionBits(), SimplifyDemandedVectorElts(), llvm::simplifyFMAFMul(), llvm::simplifyFMulInst(), simplifyInvariantGroupIntrinsic(), simplifyNeonTbl1(), simplifyReductionOperand(), llvm::simplifyRetainedKnowledge(), llvm::Splat, llvm::InstCombiner::SQ, std::swap(), llvm::InstCombiner::targetInstCombineIntrinsic(), llvm::InstCombiner::TLI, llvm::APInt::uadd_ov(), llvm::APInt::uadd_sat(), llvm::AssumptionCache::updateAffectedValues(), llvm::Value::use_empty(), llvm::MaybeAlign::valueOrOne(), visitFree(), llvm::RetainedKnowledge::WasOn, llvm::InstCombiner::Worklist, X, and Y.

◆ visitExtractElementInst()

Instruction * InstCombinerImpl::visitExtractElementInst ( ExtractElementInst EI)

Definition at line 398 of file InstCombineVectorOps.cpp.

References llvm::InstructionWorklist::addValue(), llvm::BitWidth, llvm::InstCombiner::Builder, cheapToScalarize(), llvm::count_if(), llvm::CastInst::Create(), llvm::GetElementPtrInst::Create(), llvm::ExtractElementInst::Create(), llvm::IRBuilderBase::CreateExtractElement(), llvm::BinaryOperator::CreateWithCopiedFlags(), llvm::CmpInst::CreateWithCopiedFlags(), llvm::UnaryOperator::CreateWithCopiedFlags(), findDemandedEltsByAllUsers(), FoldOpIntoSelect(), GEP, llvm::PoisonValue::get(), llvm::Value::getContext(), llvm::VectorType::getElementCount(), llvm::ExtractElementInst::getIndexOperand(), llvm::Type::getInt64Ty(), llvm::Type::getIntegerBitWidth(), llvm::UnaryOperator::getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::CmpInst::getOpcode(), llvm::User::getOperand(), getPreferredVectorIndex(), llvm::Value::getType(), llvm::ExtractElementInst::getVectorOperand(), llvm::ExtractElementInst::getVectorOperandType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), I, Idx, llvm::APInt::isAllOnes(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Cmp(), llvm::PatternMatch::m_UnOp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::APInt::setBit(), llvm::GetElementPtrInst::setIsInBounds(), SimplifyDemandedVectorElts(), llvm::simplifyExtractElementInst(), llvm::InstCombiner::SQ, llvm::InstCombiner::Worklist, X, and Y.

◆ visitExtractValueInst()

Instruction * InstCombinerImpl::visitExtractValueInst ( ExtractValueInst EV)

◆ visitFAdd()

Instruction * InstCombinerImpl::visitFAdd ( BinaryOperator I)

◆ visitFCmpInst()

Instruction * InstCombinerImpl::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 7889 of file InstCombineCompares.cpp.

References A, assert(), B, llvm::CmpInst::BAD_ICMP_PREDICATE, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APFloat::clearSign(), llvm::ConstantFoldUnaryOpOperand(), llvm::APFloat::convert(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBitCast(), llvm::InstCombiner::DL, llvm::CmpInst::FCMP_FALSE, 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_TRUE, 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::SelectPatternResult::Flavor, foldCmpLoadFromIndexedGlobal(), foldFabsWithFcmpZero(), foldFCmpFNegCommonOp(), foldFCmpIntToFPConst(), foldFCmpReciprocalAndZero(), foldOpIntoPhi(), FoldOpIntoSelect(), foldVectorCmp(), GEP, llvm::VectorType::get(), llvm::InstCombiner::getComplexity(), llvm::ConstantInt::getFalse(), llvm::IRBuilderBase::getIntNTy(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::InstCombiner::getSimplifyQuery(), llvm::APFloat::getSmallestNormalized(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::ConstantFP::getZero(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SLT, IntX, llvm::FCmpInst::isEquality(), llvm::isKnownNeverNaN(), llvm::APFloat::isZero(), llvm_unreachable, llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_FAdd(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::APFloatBase::rmNearestTiesToEven, llvm::simplifyFCmpInst(), llvm::SPF_UNKNOWN, llvm::InstCombiner::SQ, X, and Y.

◆ visitFDiv()

Instruction * InstCombinerImpl::visitFDiv ( BinaryOperator I)

◆ visitFenceInst()

Instruction * InstCombinerImpl::visitFenceInst ( FenceInst FI)

◆ visitFMul()

Instruction * InstCombinerImpl::visitFMul ( BinaryOperator I)

◆ visitFNeg()

Instruction * InstCombinerImpl::visitFNeg ( UnaryOperator I)

◆ visitFPExt()

Instruction * InstCombinerImpl::visitFPExt ( CastInst CI)

◆ visitFPToSI()

Instruction * InstCombinerImpl::visitFPToSI ( FPToSIInst FI)

Definition at line 1975 of file InstCombineCasts.cpp.

References commonCastTransforms(), foldFPtoI(), foldItoFPtoI(), and I.

◆ visitFPToUI()

Instruction * InstCombinerImpl::visitFPToUI ( FPToUIInst FI)

Definition at line 1965 of file InstCombineCasts.cpp.

References commonCastTransforms(), foldFPtoI(), foldItoFPtoI(), and I.

◆ visitFPTrunc()

Instruction * InstCombinerImpl::visitFPTrunc ( FPTruncInst CI)

◆ visitFree()

Instruction * InstCombinerImpl::visitFree ( CallInst FI,
Value FreedOp 
)

◆ visitFreeze()

Instruction * InstCombinerImpl::visitFreeze ( FreezeInst I)

◆ visitFRem()

Instruction * InstCombinerImpl::visitFRem ( BinaryOperator I)

◆ visitFSub()

Instruction * InstCombinerImpl::visitFSub ( BinaryOperator I)

◆ visitGEPOfGEP()

Instruction * InstCombinerImpl::visitGEPOfGEP ( GetElementPtrInst GEP,
GEPOperator Src 
)

◆ visitGetElementPtrInst()

Instruction * InstCombinerImpl::visitGetElementPtrInst ( GetElementPtrInst GEP)

Definition at line 2712 of file InstructionCombining.cpp.

References llvm::PHINode::addIncoming(), assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::countr_zero(), llvm::GetElementPtrInst::Create(), llvm::IRBuilderBase::CreateGEP(), llvm::GetElementPtrInst::CreateInBounds(), llvm::IRBuilderBase::CreateIntCast(), llvm::IRBuilderBase::CreatePHI(), llvm::IRBuilderBase::CreatePtrAdd(), llvm::IRBuilderBase::CreateSExt(), llvm::InstCombiner::DL, F, foldSelectGEP(), GEP, llvm::gep_type_begin(), llvm::VectorType::get(), llvm::APInt::getAllOnes(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::DataLayout::getIndexSizeInBits(), llvm::DataLayout::getIndexType(), llvm::DataLayout::getIndexTypeSizeInBits(), llvm::IRBuilderBase::getInt(), llvm::IRBuilderBase::getInt8Ty(), llvm::Constant::getNullValue(), llvm::Type::getPointerAddressSpace(), llvm::Value::getPointerDereferenceableBytes(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::GetElementPtrInst::getTypeAtIndex(), llvm::getUnderlyingObject(), llvm::SimplifyQuery::getWithInstruction(), llvm::has_single_bit(), I, llvm::Type::isIntegerTy(), llvm::isKnownNonNegative(), llvm::APInt::isNonNegative(), llvm::Type::isScalableTy(), llvm::Type::isSized(), llvm::generic_gep_type_iterator< ItTy >::isStruct(), llvm::Type::isStructTy(), llvm::Type::isVectorTy(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isZero(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_IDiv(), llvm::PatternMatch::m_NSWAdd(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_SExtLike(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::Offset, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::IRBuilderBase::SetInsertPoint(), llvm::GetElementPtrInst::setIsInBounds(), SimplifyDemandedVectorElts(), llvm::simplifyGEPInst(), llvm::InstCombiner::SQ, llvm::Value::stripAndAccumulateInBoundsConstantOffsets(), llvm::APInt::ule(), visitGEPOfGEP(), X, and Y.

◆ visitICmpInst()

Instruction * InstCombinerImpl::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 7183 of file InstCombineCompares.cpp.

References A, llvm::AllOnes, assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeCmpWithConstant(), canonicalizeICmpBool(), canonicalizeICmpPredicate(), Cond, llvm::CmpInst::Create(), llvm::ExtractValueInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateICmpSLT(), D, llvm::InstCombiner::DL, eraseInstFromFunction(), llvm::SelectPatternResult::Flavor, foldAllocaCmp(), foldICmpBinOp(), foldICmpBitCast(), foldICmpCommutative(), foldICmpEquality(), foldICmpInstWithConstant(), foldICmpInstWithConstantNotInt(), foldICmpInvariantGroup(), foldICmpOfUAddOv(), foldICmpPow2Test(), foldICmpTruncWithTruncOrExt(), foldICmpUsingBoolRange(), foldICmpUsingKnownBits(), foldICmpWithCastOp(), foldICmpWithConstant(), foldICmpWithDominatingICmp(), foldICmpWithHighBitMask(), foldICmpWithZero(), foldReductionIdiom(), foldSignBitTest(), foldVectorCmp(), llvm::Constant::getAllOnesValue(), llvm::InstCombiner::getComplexity(), llvm::InstCombiner::getFreelyInverted(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::getUnderlyingObject(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::InstCombiner::isFreeToInvert(), llvm::Type::isIntOrIntVectorTy(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::Type::isPointerTy(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_UAddWithOverflow(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), processUMulZExtIdiom(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::simplifyICmpInst(), llvm::SPF_UNKNOWN, llvm::InstCombiner::SQ, std::swap(), X, and Y.

◆ visitInsertElementInst()

Instruction * InstCombinerImpl::visitInsertElementInst ( InsertElementInst IE)

◆ visitInsertValueInst()

Instruction * InstCombinerImpl::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 1143 of file InstCombineVectorOps.cpp.

References llvm::Depth, foldAggregateConstructionIntoAggregateReuse(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::InstCombiner::replaceInstUsesWith(), llvm::simplifyInsertValueInst(), and llvm::InstCombiner::SQ.

◆ visitInstruction()

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

Specify what to return for unhandled instructions.

Definition at line 187 of file InstCombineInternal.h.

◆ visitIntToPtr()

Instruction * InstCombinerImpl::visitIntToPtr ( IntToPtrInst CI)

◆ visitInvokeInst()

Instruction * InstCombinerImpl::visitInvokeInst ( InvokeInst II)

Definition at line 3546 of file InstCombineCalls.cpp.

◆ visitLandingPadInst()

Instruction * InstCombinerImpl::visitLandingPadInst ( LandingPadInst LI)

◆ visitLoadInst()

Instruction * InstCombinerImpl::visitLoadInst ( LoadInst LI)

◆ visitLShr()

Instruction * InstCombinerImpl::visitLShr ( BinaryOperator I)

Definition at line 1240 of file InstCombineShifts.cpp.

References llvm::AllOnes, llvm::And, assert(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, commonShiftTransforms(), llvm::BinaryOperator::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateAShr(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpSLT(), llvm::IRBuilderBase::CreateIsNotNeg(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::IRBuilderBase::CreateZExt(), llvm::APInt::eq(), foldVectorBinop(), llvm::APInt::getAllOnes(), llvm::Constant::getAllOnesValue(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::Type::getScalarSizeInBits(), getScalarSizeInBits(), llvm::ConstantInt::getSigned(), llvm::Value::getType(), getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::APInt::getZExtValue(), hasNoSignedWrap(), hasNoUnsignedWrap(), llvm::Value::hasOneUse(), I, llvm::Type::isIntegerTy(), llvm::Type::isIntOrIntVectorTy(), llvm::isPowerOf2_32(), llvm::Log2_32(), llvm::APInt::logBase2(), llvm::APInt::lshr(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), RHS, setShiftFlags(), llvm::APInt::shl(), llvm::simplifyLShrInst(), llvm::InstCombiner::SQ, llvm::APInt::uge(), llvm::APInt::ugt(), llvm::APInt::ult(), X, and Y.

◆ visitMul()

Instruction * InstCombinerImpl::visitMul ( BinaryOperator I)

Definition at line 191 of file InstCombineMulDivRem.cpp.

References llvm::And, llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APInt::countr_zero(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBinaryIntrinsic(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateIsNeg(), llvm::IRBuilderBase::CreateMul(), llvm::BinaryOperator::CreateNeg(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateNSWMul(), llvm::BinaryOperator::CreateNSWNeg(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateZExt(), foldBinOpIntoSelectOrPhi(), foldBinOpOfSelectAndCastOfSelectCondition(), foldBinopWithPhiOperands(), foldMulSelectToNegate(), foldMulShl1(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::ConstantInt::getBool(), llvm::ConstantExpr::getExactLogBase2(), llvm::ConstantExpr::getNeg(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getShl(), llvm::IRBuilderBase::getTrue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), hasNoSignedWrap(), llvm::Value::hasOneUse(), I, llvm::Instruction::isExact(), llvm::Type::isIntOrIntVectorTy(), llvm::Constant::isNotMinSignedValue(), llvm::PatternMatch::m_AddLike(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NegatedPower2(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::CmpInst::makeCmpResultType(), llvm::PatternMatch::match(), llvm::Mul, N, llvm::Negator::Negate(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), SimplifyAssociativeOrCommutative(), llvm::simplifyMulInst(), llvm::InstCombiner::SQ, takeLog2(), llvm::Value::takeName(), X, and Y.

◆ visitOr()

Instruction * InstCombinerImpl::visitOr ( BinaryOperator I)

Res, Overflow = xxx_with_overflow X, C1 Try to canonicalize the pattern "Overflow | icmp pred Res, C2" into "Overflow | icmp pred X, C2 +/- C1".

Definition at line 3427 of file InstCombineAndOrXor.cpp.

References A, llvm::AllOnes, llvm::And, B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(), canonicalizeLogicFirst(), llvm::InstCombiner::computeKnownBits(), Concat, llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateFNeg(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateICmpSGT(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateLogicalOr(), llvm::BinaryOperator::CreateNot(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), D, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, foldBinOpIntoSelectOrPhi(), foldBinOpShiftWithShift(), foldBinopWithPhiOperands(), foldBitwiseLogicWithIntrinsics(), foldComplexAndOrPatterns(), foldOrToXor(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::Constant::getAllOnesValue(), llvm::BinaryOpIntrinsic::getBinaryOp(), llvm::IRBuilderBase::GetInsertBlock(), llvm::BinaryOpIntrinsic::getLHS(), llvm::Constant::getNullValue(), llvm::BasicBlock::getParent(), llvm::BinaryOpIntrinsic::getRHS(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Function::hasFnAttribute(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_NE, llvm::APInt::isAllOnes(), llvm::ICmpInst::isEquality(), llvm::Type::isFloatingPointTy(), llvm::Type::isIEEE(), llvm::Type::isIntOrIntVectorTy(), llvm::CmpInst::isSigned(), llvm::BinaryOpIntrinsic::isSigned(), isZero(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_DisjointOr(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_WithOverflowInst(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZeroInt(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), matchBSwapOrBitReverse(), matchDeMorgansLaws(), matchFunnelShift(), matchOrConcat(), llvm::matchSimpleRecurrence(), llvm::Mul, llvm::KnownBits::One, llvm::Or, reassociateFCmps(), reassociateForUses(), llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::APInt::sadd_ov(), SimplifyAddWithRemainder(), simplifyAndOrWithOpReplaced(), SimplifyAssociativeOrCommutative(), SimplifyDemandedInstructionBits(), llvm::simplifyOrInst(), sinkNotIntoOtherHandOfLogicalOp(), llvm::InstCombiner::SQ, llvm::APInt::ssub_ov(), std::swap(), llvm::Value::takeName(), tryFoldInstWithCtpopWithNot(), llvm::APInt::uadd_ov(), llvm::APInt::usub_ov(), X, llvm::Xor, and Y.

◆ visitPHINode()

Instruction * InstCombinerImpl::visitPHINode ( PHINode PN)

Definition at line 1436 of file InstCombinePHI.cpp.