29 #define DEBUG_TYPE "instcombine"
31 STATISTIC(NumDeadStore,
"Number of dead stores eliminated");
32 STATISTIC(NumGlobalCopies,
"Number of allocas copied from constant global");
39 return GV->isConstant();
42 if (CE->getOpcode() == Instruction::BitCast ||
43 CE->getOpcode() == Instruction::AddrSpaceCast ||
44 CE->getOpcode() == Instruction::GetElementPtr)
66 while (!ValuesToInspect.
empty()) {
68 const bool IsOffset = ValuePair.second;
69 for (
auto &U : ValuePair.first->uses()) {
70 auto *
I = cast<Instruction>(U.getUser());
72 if (
auto *LI = dyn_cast<LoadInst>(
I)) {
74 if (!LI->isSimple())
return false;
78 if (isa<BitCastInst>(
I) || isa<AddrSpaceCastInst>(
I)) {
83 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(
I)) {
96 unsigned DataOpNo = CS.getDataOperandNo(&U);
97 bool IsArgOperand = CS.isArgOperand(&U);
100 if (IsArgOperand && CS.isInAllocaArgument(DataOpNo))
106 if (CS.onlyReadsMemory() &&
107 (CS.getInstruction()->use_empty() || CS.doesNotCapture(DataOpNo)))
112 if (IsArgOperand && CS.isByValArgument(DataOpNo))
118 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
119 II->getIntrinsicID() == Intrinsic::lifetime_end) {
120 assert(II->use_empty() &&
"Lifetime markers have no result to use!");
134 if (U.getOperandNo() == 1) {
140 if (TheCopy)
return false;
144 if (IsOffset)
return false;
147 if (U.getOperandNo() != 0)
return false;
207 while (isa<AllocaInst>(*It) || isa<DbgInfoIntrinsic>(*It))
215 Value *Idx[2] = {NullIdx, NullIdx};
251 class PointerReplacer {
267 void PointerReplacer::findLoadAndReplace(
Instruction &
I) {
268 for (
auto U : I.
users()) {
272 DEBUG(
dbgs() <<
"Found pointer user: " << *U <<
'\n');
273 if (isa<LoadInst>(Inst)) {
277 }
else if (isa<GetElementPtrInst>(Inst) || isa<BitCastInst>(Inst)) {
278 Path.push_back(Inst);
279 findLoadAndReplace(*Inst);
287 Value *PointerReplacer::getReplacement(
Value *V) {
288 auto Loc = WorkMap.find(V);
289 if (Loc != WorkMap.end())
295 if (getReplacement(I))
298 if (
auto *
LT = dyn_cast<LoadInst>(I)) {
299 auto *V = getReplacement(
LT->getPointerOperand());
300 assert(V &&
"Operand not replaced");
303 IC.InsertNewInstWith(NewI, *
LT);
304 IC.replaceInstUsesWith(*
LT, NewI);
306 }
else if (
auto *
GEP = dyn_cast<GetElementPtrInst>(I)) {
307 auto *V = getReplacement(
GEP->getPointerOperand());
308 assert(V &&
"Operand not replaced");
313 IC.InsertNewInstWith(NewI, *
GEP);
316 }
else if (
auto *BC = dyn_cast<BitCastInst>(I)) {
317 auto *V = getReplacement(BC->getOperand(0));
318 assert(V &&
"Operand not replaced");
322 IC.InsertNewInstWith(NewI, *BC);
332 auto *PT = cast<PointerType>(I.
getType());
333 auto *NT = cast<PointerType>(V->
getType());
334 assert(PT != NT && PT->getElementType() == NT->getElementType() &&
338 findLoadAndReplace(I);
365 if (FirstInst != &AI) {
404 Copy->getSource(), AI.
getAlignment(), DL, &AI, &AC, &DT);
405 if (AI.getAlignment() <= SourceAlign &&
407 DEBUG(
dbgs() <<
"Found alloca equal to global: " << AI <<
'\n');
408 DEBUG(
dbgs() <<
" memcpy = " << *Copy <<
'\n');
409 for (
unsigned i = 0, e = ToDelete.
size(); i != e; ++i)
411 Constant *TheSrc = cast<Constant>(Copy->getSource());
412 auto *SrcTy = TheSrc->
getType();
414 SrcTy->getPointerAddressSpace());
417 if (AI.getType()->getPointerAddressSpace() ==
418 SrcTy->getPointerAddressSpace()) {
424 PointerReplacer PtrReplacer(*
this);
425 PtrReplacer.replacePointer(AI, Cast);
452 const Twine &Suffix =
"") {
454 "can't fold an atomic load to requested type");
466 for (
const auto &MDPair : MD) {
467 unsigned ID = MDPair.first;
514 "can't fold an atomic store of requested type");
525 for (
const auto &MDPair : MD) {
526 unsigned ID = MDPair.first;
607 return SI &&
SI->getPointerOperand() != &LI &&
608 !
SI->getPointerOperand()->isSwiftError();
615 auto *
SI = cast<StoreInst>(*UI++);
631 if (
auto* CI = dyn_cast<CastInst>(LI.
user_back()))
632 if (CI->isNoopCast(DL))
658 if (
auto *
ST = dyn_cast<StructType>(T)) {
660 auto NumElements =
ST->getNumElements();
661 if (NumElements == 1) {
675 if (SL->hasPadding())
687 for (
unsigned i = 0; i < NumElements; i++) {
688 Value *Indices[2] = {
699 L->setAAMetadata(AAMD);
707 if (
auto *AT = dyn_cast<ArrayType>(T)) {
708 auto *ET = AT->getElementType();
709 auto NumElements = AT->getNumElements();
710 if (NumElements == 1) {
738 for (uint64_t i = 0; i < NumElements; i++) {
739 Value *Indices[2] = {
749 L->setAAMetadata(AAMD);
776 if (!Visited.
insert(P).second)
785 if (
PHINode *PN = dyn_cast<PHINode>(P)) {
786 for (
Value *IncValue : PN->incoming_values())
792 if (GA->isInterposable())
800 if (
AllocaInst *AI = dyn_cast<AllocaInst>(P)) {
801 if (!AI->getAllocatedType()->isSized())
817 if (!GV->hasDefinitiveInitializer() || !GV->isConstant())
821 if (InitSize > MaxSize)
827 }
while (!Worklist.
empty());
858 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(V))
870 Idx = FirstNZIdx(GEPI);
879 if (!AllocTy || !AllocTy->isSized())
888 auto IsAllNonNegative = [&]() {
889 for (
unsigned i = Idx+1, e = GEPI->
getNumOperands(); i != e; ++i) {
916 template <
typename T>
926 MemI.setOperand(MemI.getPointerOperandIndex(), NewGEPI);
936 const Value *GEPI0 = GEPI->getOperand(0);
937 if (isa<ConstantPointerNull>(GEPI0) && GEPI->getPointerAddressSpace() == 0)
940 if (isa<UndefValue>(Op) ||
957 unsigned EffectiveLoadAlign =
960 if (KnownAlign > EffectiveLoadAlign)
962 else if (LoadAlign == 0)
978 bool IsLoadCSE =
false;
1024 SI->getOperand(1)->getName()+
".val");
1026 SI->getOperand(2)->getName()+
".val");
1036 if (isa<ConstantPointerNull>(
SI->getOperand(1)) &&
1043 if (isa<ConstantPointerNull>(
SI->getOperand(2)) &&
1069 while (
auto *IV = dyn_cast<InsertValueInst>(V)) {
1073 auto *W =
E->getVectorOperand();
1079 if (!CI || IV->getNumIndices() != 1 || CI->getZExtValue() != *IV->idx_begin())
1081 V = IV->getAggregateOperand();
1083 if (!isa<UndefValue>(V) ||!U)
1086 auto *UT = cast<VectorType>(U->
getType());
1093 if (
auto *AT = dyn_cast<ArrayType>(VT)) {
1094 if (AT->getNumElements() != UT->getNumElements())
1097 auto *
ST = cast<StructType>(VT);
1098 if (
ST->getNumElements() != UT->getNumElements())
1100 for (
const auto *EltT :
ST->elements()) {
1101 if (EltT != UT->getElementType())
1141 if (
auto *BC = dyn_cast<BitCastInst>(V)) {
1142 V = BC->getOperand(0);
1172 if (
auto *
ST = dyn_cast<StructType>(T)) {
1174 unsigned Count =
ST->getNumElements();
1185 if (SL->hasPadding())
1196 AddrName +=
".repack";
1200 for (
unsigned i = 0; i < Count; i++) {
1201 Value *Indices[2] = {
1212 NS->setAAMetadata(AAMD);
1218 if (
auto *AT = dyn_cast<ArrayType>(T)) {
1220 auto NumElements = AT->getNumElements();
1221 if (NumElements == 1) {
1244 AddrName +=
".repack";
1250 for (uint64_t i = 0; i < NumElements; i++) {
1251 Value *Indices[2] = {
1282 if (A == B)
return true;
1289 if (isa<BinaryOperator>(A) ||
1292 isa<GetElementPtrInst>(A))
1294 if (cast<Instruction>(A)->isIdenticalToWhenDefined(BI))
1313 unsigned EffectiveStoreAlign =
1316 if (KnownAlign > EffectiveStoreAlign)
1318 else if (StoreAlign == 0)
1338 if (isa<AllocaInst>(Ptr))
1341 if (isa<AllocaInst>(
GEP->getOperand(0))) {
1342 if (
GEP->getOperand(0)->hasOneUse())
1352 for (
unsigned ScanInsts = 6; BBI != SI.
getParent()->
begin() && ScanInsts;
1357 if (isa<DbgInfoIntrinsic>(BBI) ||
1358 (isa<BitCastInst>(BBI) && BBI->getType()->isPointerTy())) {
1363 if (
StoreInst *PrevSI = dyn_cast<StoreInst>(BBI)) {
1378 if (
LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
1390 if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory() || BBI->mayThrow())
1396 if (!isa<UndefValue>(Val)) {
1405 if (isa<UndefValue>(Val))
1414 }
while (isa<DbgInfoIntrinsic>(BBI) ||
1415 (isa<BitCastInst>(BBI) && BBI->getType()->isPointerTy()));
1416 if (
BranchInst *BI = dyn_cast<BranchInst>(BBI))
1417 if (BI->isUnconditional())
1418 if (SimplifyStoreAtEndOfBlock(SI))
1432 bool InstCombiner::SimplifyStoreAtEndOfBlock(
StoreInst &SI) {
1434 "this code has not been auditted for volatile or ordered store case");
1466 if (StoreBB == DestBB || OtherBB == DestBB)
1472 if (!OtherBr || BBI == OtherBB->
begin())
1478 if (OtherBr->isUnconditional()) {
1481 while (isa<DbgInfoIntrinsic>(BBI) ||
1482 (isa<BitCastInst>(BBI) && BBI->getType()->isPointerTy())) {
1483 if (BBI==OtherBB->
begin())
1496 if (OtherBr->getSuccessor(0) != StoreBB &&
1497 OtherBr->getSuccessor(1) != StoreBB)
1505 if ((OtherStore = dyn_cast<StoreInst>(BBI))) {
1513 if (BBI->mayReadFromMemory() || BBI->mayThrow() ||
1514 BBI->mayWriteToMemory() || BBI == OtherBB->
begin())
Value * getValueOperand()
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
bool isNonIntegralPointerType(PointerType *PT) const
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Type * getSourceElementType() const
STATISTIC(NumFunctions,"Total number of functions")
bool isVolatile() const
Return true if this is a store to a volatile memory location.
void setAlignment(unsigned Align)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
unsigned getNumOperands() const
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
cl::opt< unsigned > DefMaxInstsToScan
The default number of maximum instructions to scan in the block, used by FindAvailableLoadedValue().
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
const DataLayout & getDataLayout() const
static bool isDereferenceableForAllocaSize(const Value *V, const AllocaInst *AI, const DataLayout &DL)
Returns true if V is dereferenceable for size of alloca.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
void Add(Instruction *I)
Add - Add the specified instruction to the worklist if it isn't already in it.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
static LoadInst * combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewTy, const Twine &Suffix="")
Helper to combine a load to a new type.
An instruction for reading from memory.
static bool pointsToConstantGlobal(Value *V)
pointsToConstantGlobal - Return true if V (possibly indirectly) points to some part of a constant glo...
uint64_t MaxArraySizeForCombine
Maximum size of array considered when transforming.
static IntegerType * getInt64Ty(LLVMContext &C)
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Get all metadata attached to this Instruction.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this store instruction.
static bool isOnlyCopiedFromConstantGlobal(Value *V, MemTransferInst *&TheCopy, SmallVectorImpl< Instruction * > &ToDelete)
isOnlyCopiedFromConstantGlobal - Recursively walk the uses of a (derived) pointer to an alloca...
bool isSafeToLoadUnconditionally(Value *V, unsigned Align, const DataLayout &DL, Instruction *ScanFrom=nullptr, const DominatorTree *DT=nullptr)
Return true if we know that executing a load from this value cannot trap.
Type * getPointerElementType() const
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile=false)
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this load instruction.
bool isNonNegative() const
Returns true if this value is known to be non-negative.
This class represents the LLVM 'select' instruction.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this store instruction.
const APInt & getValue() const
Return the constant as an APInt value reference.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Value * FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=DefMaxInstsToScan, AliasAnalysis *AA=nullptr, bool *IsLoadCSE=nullptr, unsigned *NumScanedInst=nullptr)
Scan backwards to see if we have the value of the given load available locally within a small number ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Instruction * eraseInstFromFunction(Instruction &I)
Combiner aware instruction erasure.
static Instruction * replaceGEPIdxWithZero(InstCombiner &IC, Value *Ptr, T &MemI)
The core instruction combiner logic.
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
void setName(const Twine &Name)
Change the name of the value.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
LLVM_NODISCARD bool empty() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
A constant value that is initialized with an expression using other constant values.
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
bool mayReadFromMemory() const
Return true if this instruction may read memory.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
static Instruction * simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI)
This class represents a no-op cast from one type to another.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
LoadInst * CreateLoad(Value *Ptr, const char *Name)
static Instruction * combineLoadToOperationType(InstCombiner &IC, LoadInst &LI)
Combine loads to match the type of their uses' value after looking through intervening bitcasts...
static bool equivalentAddressValues(Value *A, Value *B)
equivalentAddressValues - Test if A and B will obviously have the same value.
static bool unpackStoreToAggregate(InstCombiner &IC, StoreInst &SI)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
void setAAMetadata(const AAMDNodes &N)
Sets the metadata on this instruction from the AAMDNodes structure.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
uint64_t getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
Conditional or Unconditional Branch instruction.
void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
This is an important base class in LLVM.
PointerType * getType() const
Overload to return most specific pointer type.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static StoreInst * combineStoreToNewValue(InstCombiner &IC, StoreInst &SI, Value *V)
Combine a store to a new type.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
Instruction * visitAllocaInst(AllocaInst &AI)
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
Value * getPointerOperand()
self_iterator getIterator()
void setAlignment(unsigned Align)
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
LLVMContext & getContext() const
All values hold a context through their type.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
InstCombineWorklist & Worklist
A worklist of the instructions that need to be simplified.
static bool canSimplifyNullLoadOrGEP(LoadInst &LI, Value *Op)
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Iterator for intrusive lists based on ilist_node.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
static bool isSupportedAtomicType(Type *Ty)
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
bool isSwiftError() const
Return true if this value is a swifterror value.
LLVM_NODISCARD T pop_back_val()
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
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.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
const BasicBlock & getEntryBlock() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
static bool combineStoreToValueType(InstCombiner &IC, StoreInst &SI)
Combine stores to match the type of value being stored.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
static bool isObjectSizeLessThanOrEq(Value *V, uint64_t MaxSize, const DataLayout &DL)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
llvm_unreachable("Unknown RegBank!")
bool mayThrow() const
Return true if this instruction may throw an exception.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Value * getSource() const
This is just like getRawSource, but it strips off any cast instructions that feed it...
This class wraps the llvm.memcpy/memmove intrinsics.
void emplace_back(ArgTypes &&...Args)
bool isAggregateType() const
Return true if the type is an aggregate type.
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
static Value * likeBitCastFromVector(InstCombiner &IC, Value *V)
Look for extractelement/insertvalue sequence that acts like a bitcast.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Instruction * InsertNewInstBefore(Instruction *New, Instruction &Old)
Inserts an instruction New before instruction Old.
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
static bool canReplaceGEPIdxWithZero(InstCombiner &IC, GetElementPtrInst *GEPI, Instruction *MemI, unsigned &Idx)
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
Instruction * visitLoadInst(LoadInst &LI)
LLVM Value Representation.
void setAlignment(unsigned Align)
This file provides internal interfaces used to implement the InstCombine.
Instruction * visitStoreInst(StoreInst &SI)
const Value * getArraySize() const
Get the number of elements allocated.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
StringRef - Represent a constant reference to a string, i.e.
static Expected< std::string > replace(StringRef S, StringRef From, StringRef To)
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one...
bool isDereferenceableAndAlignedPointer(const Value *V, unsigned Align, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested...
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Value * getPointerOperand()
static Instruction * unpackLoadToAggregate(InstCombiner &IC, LoadInst &LI)
Instruction * visitAllocSite(Instruction &FI)
const BasicBlock * getParent() const
A wrapper class for inspecting calls to intrinsic functions.
an instruction to allocate memory on the stack