15 #ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
16 #define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
32 #define DEBUG_TYPE "instcombine"
38 class TargetLibraryInfo;
53 if (isa<Instruction>(V)) {
61 return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
84 if (isa<ConstantInt>(V))
90 return WillInvertAllUses;
95 if (BO->getOpcode() == Instruction::Add ||
96 BO->getOpcode() == Instruction::Sub)
97 if (isa<Constant>(BO->getOperand(0)) || isa<Constant>(BO->getOperand(1)))
98 return WillInvertAllUses;
123 case Intrinsic::uadd_with_overflow:
125 case Intrinsic::sadd_with_overflow:
127 case Intrinsic::usub_with_overflow:
129 case Intrinsic::ssub_with_overflow:
131 case Intrinsic::umul_with_overflow:
133 case Intrinsic::smul_with_overflow:
147 : Worklist(WL), AC(AC) {}
154 using namespace llvm::PatternMatch;
155 if (
match(I, m_Intrinsic<Intrinsic::assume>()))
156 AC->registerAssumption(cast<CallInst>(I));
166 :
public InstVisitor<InstCombiner, Instruction *> {
179 const bool MinimizeSize;
201 : Worklist(Worklist), Builder(Builder), MinimizeSize(MinimizeSize),
202 AA(AA), AC(AC), TLI(TLI), DT(DT), DL(DL), LI(LI), MadeIRChange(
false) {}
341 const unsigned SIOpd);
344 bool ShouldChangeType(
Type *From,
Type *To)
const;
346 Value *dyn_castFNegVal(
Value *V,
bool NoSignedZero =
false)
const;
377 bool DoXform =
true);
394 "New instruction already inserted into a basic block!");
404 return InsertNewInstBefore(New, Old);
418 Worklist.AddUsersToWorkList(I);
425 DEBUG(
dbgs() <<
"IC: Replacing " << I <<
"\n"
426 <<
" with " << *V <<
'\n');
448 DEBUG(
dbgs() <<
"IC: ERASE " << I <<
'\n');
450 assert(I.
use_empty() &&
"Cannot erase instruction that is used!");
479 unsigned Depth = 0,
Instruction *CxtI =
nullptr)
const {
509 APInt &KnownOne,
unsigned Depth,
511 bool SimplifyDemandedBits(
Use &U,
APInt DemandedMask,
APInt &KnownZero,
512 APInt &KnownOne,
unsigned Depth = 0);
521 bool SimplifyDemandedInstructionBits(
Instruction &Inst);
524 APInt &UndefElts,
unsigned Depth = 0);
556 Value *EvaluateInDifferentType(
Value *V,
Type *Ty,
bool isSigned);
IRBuilder< true, TargetFolder, InstCombineIRInserter > BuilderTy
An IRBuilder that automatically inserts new instructions into the worklist.
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
EmitGEPOffset - Given a getelementptr instruction/constantexpr, emit the code necessary to compute th...
ReturnInst - Return a value (possibly void), from a function.
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
Instruction * InsertNewInstWith(Instruction *New, Instruction &Old)
Same as InsertNewInstBefore, but also sets the debug loc.
A parsed version of the target data layout string in and methods for querying it. ...
This class is the base class for the comparison instructions.
static bool IsFreeToInvert(Value *V, bool WillInvertAllUses)
Return true if the specified value is free to invert (apply ~ to).
Base class for instruction visitors.
OverflowResult computeOverflowForUnsignedMul(Value *LHS, Value *RHS, const Instruction *CxtI)
This class represents zero extension of integer types.
unsigned getNumOperands() const
InstCombineIRInserter(InstCombineWorklist &WL, AssumptionCache *AC)
CallInst - This class represents a function call, abstracting a target machine's calling convention...
void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
const DataLayout & getDataLayout() const
A cache of .assume calls within a function.
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
MemSetInst - This class wraps the llvm.memset intrinsic.
This class represents a sign extension of integer types.
LoadInst - an instruction for reading from memory.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static OverflowCheckFlavor IntrinsicIDToOverflowCheckFlavor(unsigned ID)
Returns the OverflowCheckFlavor corresponding to a overflow_with_op intrinsic.
void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne, unsigned Depth, Instruction *CxtI) const
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool match(Val *V, const Pattern &P)
InstCombiner(InstCombineWorklist &Worklist, BuilderTy *Builder, bool MinimizeSize, AliasAnalysis *AA, AssumptionCache *AC, TargetLibraryInfo *TLI, DominatorTree *DT, const DataLayout &DL, LoopInfo *LI)
This class represents a conversion between pointers from one address space to another.
static unsigned getComplexity(Value *V)
Assign a complexity or rank value to LLVM Values.
SelectInst - This class represents the LLVM 'select' instruction.
OverflowCheckFlavor
Specific patterns of overflow check idioms that we match.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is the base class for all instructions that perform data casts.
StructType - Class to represent struct types.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
The core instruction combiner logic.
static Constant * AddOne(Constant *C)
Add one to a Constant.
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
MaskedValueIsZero - Return true if 'V & Mask' is known to be zero.
OverflowResult computeOverflowForUnsignedAdd(Value *LHS, Value *RHS, const Instruction *CxtI)
AssumptionCache * getAssumptionCache() const
This class represents a cast from a pointer to an integer.
DominatorTree * getDominatorTree() const
This instruction compares its operands according to the predicate given to the constructor.
This class represents a no-op cast from one type to another.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
StoreInst - an instruction for storing to memory.
Instruction * visitInstruction(Instruction &I)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
This class represents a cast from floating point to signed integer.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
This class represents a truncation of integer types.
PointerType - Class to represent pointers.
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
OverflowResult computeOverflowForUnsignedAdd(Value *LHS, Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
void setDebugLoc(DebugLoc Loc)
setDebugLoc - Set the debug location information for this instruction.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
BranchInst - Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
Instruction * ReplaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
const InstListType & getInstList() const
Return the underlying instruction list container.
OverflowResult computeOverflowForUnsignedMul(Value *LHS, Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
iterator insert(iterator where, NodeTy *New)
Instruction * CreateOverflowTuple(IntrinsicInst *II, Value *Result, Constant *Overflow)
Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value...
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
static bool isNot(const Value *V)
static Constant * get(StructType *T, ArrayRef< Constant * > V)
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeSignBit - Determine whether the sign bit is known to be zero or one.
This class represents a cast from an integer to a pointer.
InstCombineWorklist - This is the worklist management logic for InstCombine.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
InstCombineWorklist & Worklist
A worklist of the instructions that need to be simplified.
This provides the default implementation of the IRBuilder 'InsertHelper' method that is called whenev...
MemIntrinsic - This is the common base class for memset/memcpy/memmove.
This is the shared class of boolean and integer constants.
LoopInfo * getLoopInfo() const
Type * getType() const
All values are typed, get the type of this value.
SelectPatternFlavor
Specific patterns of select instructions we can match.
Provides information about what library functions are available for the current target.
unsigned ComputeNumSignBits(Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeNumSignBits - Return the number of times the sign bit of the register is replicated into the o...
This class represents a cast from floating point to unsigned integer.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool isNeg(const Value *V)
Check if the given Value is a NEG, FNeg, or NOT instruction.
Class for arbitrary precision integers.
TargetLibraryInfo * getTargetLibraryInfo() const
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Instruction * InsertNewInstBefore(Instruction *New, Instruction &Old)
Inserts an instruction New before instruction Old.
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, unsigned Depth=0, Instruction *CxtI=nullptr) const
bool MaskedValueIsZero(Value *V, const APInt &Mask, unsigned Depth=0, Instruction *CxtI=nullptr) const
SwitchInst - Multiway switch.
This class represents a truncation of floating point types.
unsigned ComputeNumSignBits(Value *Op, unsigned Depth=0, Instruction *CxtI=nullptr) const
LLVM Value Representation.
An IRBuilder inserter that adds new instructions to the instcombine worklist.
Instruction * EraseInstFromFunction(Instruction &I)
Combiner aware instruction erasure.
InvokeInst - Invoke instruction.
C - The default llvm calling convention, compatible with C.
const BasicBlock * getParent() const
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...