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))
91 for (
unsigned i = 0;
i != NumElts; ++
i) {
96 if (isa<UndefValue>(Elt))
99 if (!isa<ConstantInt>(Elt))
108 return WillInvertAllUses;
114 BO->getOpcode() == Instruction::Sub)
115 if (isa<Constant>(BO->getOperand(0)) || isa<Constant>(BO->getOperand(1)))
116 return WillInvertAllUses;
141 case Intrinsic::uadd_with_overflow:
143 case Intrinsic::sadd_with_overflow:
145 case Intrinsic::usub_with_overflow:
147 case Intrinsic::ssub_with_overflow:
149 case Intrinsic::umul_with_overflow:
151 case Intrinsic::smul_with_overflow:
161 :
public InstVisitor<InstCombiner, Instruction *> {
174 const bool MinimizeSize;
176 const bool ExpensiveCombines;
194 bool MinimizeSize,
bool ExpensiveCombines,
AliasAnalysis *AA,
197 : Worklist(Worklist), Builder(Builder), MinimizeSize(MinimizeSize),
198 ExpensiveCombines(ExpensiveCombines), AA(AA), AC(AC), TLI(TLI), DT(DT),
199 DL(DL), LI(LI), MadeIRChange(
false) {}
314 const unsigned SIOpd);
317 bool ShouldChangeType(
unsigned FromBitWidth,
unsigned ToBitWidth)
const;
318 bool ShouldChangeType(
Type *From,
Type *To)
const;
320 Value *dyn_castFNegVal(
Value *V,
bool NoSignedZero =
false)
const;
333 bool shouldOptimizeCast(
CastInst *CI);
353 bool transformConstExprCastCall(
CallSite CS);
370 bool DoTransform =
true);
404 "New instruction already inserted into a basic block!");
414 return InsertNewInstBefore(New, Old);
428 Worklist.AddUsersToWorkList(I);
435 DEBUG(
dbgs() <<
"IC: Replacing " << I <<
"\n"
436 <<
" with " << *V <<
'\n');
458 DEBUG(
dbgs() <<
"IC: ERASE " << I <<
'\n');
465 if (
auto *Inst = dyn_cast<Instruction>(Operand))
521 bool SimplifyDemandedBits(
Use &U,
const APInt &DemandedMask,
APInt &KnownZero,
531 bool SimplifyDemandedInstructionBits(
Instruction &Inst);
637 bool isSigned,
bool Inside);
640 bool SimplifyStoreAtEndOfBlock(
StoreInst &SI);
644 Value *EvaluateInDifferentType(
Value *V,
Type *Ty,
bool isSigned);
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from th...
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void computeKnownBits(const 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...
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
This class represents a function call, abstracting a target machine's calling convention.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
const DataLayout & getDataLayout() const
A cache of .assume calls within a function.
This instruction constructs a fixed permutation of two input vectors.
This class wraps the llvm.memset intrinsic.
This class represents a sign extension of integer types.
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)
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.
This class represents the LLVM 'select' instruction.
OverflowCheckFlavor
Specific patterns of overflow check idioms that we match.
This is the base class for all instructions that perform data casts.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
Instruction * eraseInstFromFunction(Instruction &I)
Combiner aware instruction erasure.
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.
OverflowResult computeOverflowForUnsignedAdd(Value *LHS, Value *RHS, const Instruction *CxtI)
This class represents a cast from a pointer to an integer.
This represents the llvm.va_start intrinsic.
This instruction compares its operands according to the predicate given to the constructor.
Function Alias Analysis false
TargetLibraryInfo & getTargetLibraryInfo() const
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)...
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
Instruction * visitInstruction(Instruction &I)
Specify what to return for unhandled instructions.
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.
Class to represent pointers.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
This instruction inserts a single (scalar) element into a VectorType value.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
void setDebugLoc(DebugLoc Loc)
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...
Conditional or Unconditional Branch instruction.
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if 'V & Mask' is known to be zero.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
IRBuilder< TargetFolder, IRBuilderCallbackInserter > BuilderTy
An IRBuilder that automatically inserts new instructions into the worklist.
const InstListType & getInstList() const
Return the underlying instruction list container.
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.
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)
self_iterator getIterator()
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
DominatorTree & getDominatorTree() const
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)
Static factory methods - Return an 'undef' object of the specified type.
InstCombiner(InstCombineWorklist &Worklist, BuilderTy *Builder, bool MinimizeSize, bool ExpensiveCombines, AliasAnalysis *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, DominatorTree &DT, const DataLayout &DL, LoopInfo *LI)
InstCombineWorklist & Worklist
A worklist of the instructions that need to be simplified.
This is the common base class for memset/memcpy/memmove.
This is the shared class of boolean and integer constants.
LoopInfo * getLoopInfo() const
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return the number of times the sign bit of the register is replicated into the other bits...
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.
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.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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.
unsigned getVectorNumElements() const
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
iterator insert(iterator where, pointer New)
void ComputeSignBit(const Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine whether the sign bit is known to be zero or one.
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
AssumptionCache & getAssumptionCache() const
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
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
This represents the llvm.va_copy intrinsic.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
This class represents a truncation of floating point types.
unsigned ComputeNumSignBits(Value *Op, unsigned Depth=0, Instruction *CxtI=nullptr) const
LLVM Value Representation.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
const BasicBlock * getParent() const
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
A wrapper class for inspecting calls to intrinsic functions.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.