Go to the documentation of this file.
32 const APInt APAlign(Offset.getBitWidth(), Alignment.value());
34 return BA >= Alignment && !(Offset & (APAlign - 1));
51 if (!Visited.
insert(V).second)
58 if (
const SelectInst *Sel = dyn_cast<SelectInst>(V)) {
60 Size,
DL, CtxI, DT, TLI, Visited,
63 Size,
DL, CtxI, DT, TLI, Visited,
69 if (BC->getSrcTy()->isPointerTy())
71 BC->getOperand(0), Alignment, Size,
DL, CtxI, DT, TLI,
75 bool CheckForNonNull, CheckForFreed;
76 APInt KnownDerefBytes(Size.getBitWidth(),
87 APInt Offset(
DL.getTypeStoreSizeInBits(Ty), 0);
97 V, {Attribute::Dereferenceable, Attribute::Alignment},
nullptr,
101 if (RK.
AttrKind == Attribute::Alignment)
103 if (RK.
AttrKind == Attribute::Dereferenceable)
105 if (AlignRK && DerefRK && AlignRK.
ArgValue >= Alignment.value() &&
106 DerefRK.
ArgValue >= Size.getZExtValue())
120 APInt Offset(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
121 if (!
GEP->accumulateConstantOffset(
DL, Offset) || Offset.isNegative() ||
122 !Offset.urem(
APInt(Offset.getBitWidth(), Alignment.value()))
135 Base, Alignment, Offset + Size.sextOrTrunc(Offset.getBitWidth()),
DL,
140 if (
const GCRelocateInst *RelocateInst = dyn_cast<GCRelocateInst>(V))
142 Alignment, Size,
DL, CtxI, DT,
147 Size,
DL, CtxI, DT, TLI,
150 if (
const auto *Call = dyn_cast<CallBase>(V)) {
170 APInt KnownDerefBytes(Size.getBitWidth(), ObjSize);
179 APInt Offset(
DL.getTypeStoreSizeInBits(Ty), 0);
213 if (!Ty->
isSized() || isa<ScalableVectorType>(Ty))
222 DL.getTypeStoreSize(Ty));
256 if (isa<BinaryOperator>(A) || isa<CastInst>(A) || isa<PHINode>(A) ||
257 isa<GetElementPtrInst>(A))
259 if (cast<Instruction>(A)->isIdenticalToWhenDefined(BI))
273 DL.getTypeStoreSize(LI->
getType()).getFixedSize());
282 HeaderFirstNonPHI, &DT);
286 auto *AddRec = dyn_cast<SCEVAddRecExpr>(SE.
getSCEV(Ptr));
287 if (!AddRec || AddRec->getLoop() != L || !AddRec->isAffine())
289 auto* Step = dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(SE));
293 if (Step->getAPInt() != EltSize)
300 const APInt AccessSize = TC * EltSize;
302 auto *StartS = dyn_cast<SCEVUnknown>(AddRec->getStart());
311 if (EltSize.urem(Alignment.value()) != 0)
314 HeaderFirstNonPHI, &DT);
341 if (Size.getBitWidth() > 64)
343 const uint64_t LoadSize = Size.getZExtValue();
362 if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
363 !isa<DbgInfoIntrinsic>(BBI))
369 if (
LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
373 if (LI->isVolatile())
375 AccessedPtr = LI->getPointerOperand();
376 AccessedTy = LI->getType();
377 AccessedAlign = LI->getAlign();
378 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(BBI)) {
380 if (
SI->isVolatile())
382 AccessedPtr =
SI->getPointerOperand();
383 AccessedTy =
SI->getValueOperand()->getType();
384 AccessedAlign =
SI->getAlign();
388 if (AccessedAlign < Alignment)
392 if (AccessedPtr == V &&
393 LoadSize <=
DL.getTypeStoreSize(AccessedTy))
397 LoadSize <=
DL.getTypeStoreSize(AccessedTy))
408 APInt Size(
DL.getIndexTypeSizeInBits(V->
getType()),
DL.getTypeStoreSize(Ty));
420 cl::desc(
"Use this to specify the default maximum number of instructions "
421 "to scan backward from a given instruction, when searching for "
422 "available loaded value"));
427 unsigned MaxInstsToScan,
429 unsigned *NumScanedInst) {
431 if (!
Load->isUnordered())
436 ScanBB, ScanFrom, MaxInstsToScan,
AA, IsLoad,
444 const Value *StorePtr,
447 APInt LoadOffset(
DL.getIndexTypeSizeInBits(LoadPtr->
getType()), 0);
448 APInt StoreOffset(
DL.getIndexTypeSizeInBits(StorePtr->
getType()), 0);
450 DL, LoadOffset,
false);
452 DL, StoreOffset,
false);
453 if (LoadBase != StoreBase)
458 LoadOffset + LoadAccessSize.toRaw());
460 StoreOffset + StoreAccessSize.toRaw());
465 Type *AccessTy,
bool AtLeastAtomic,
470 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
473 if (LI->isAtomic() < AtLeastAtomic)
493 if (
SI->isAtomic() < AtLeastAtomic)
496 Value *StorePtr =
SI->getPointerOperand()->stripPointerCasts();
503 Value *Val =
SI->getValueOperand();
508 TypeSize LoadSize =
DL.getTypeSizeInBits(AccessTy);
510 if (
auto *
C = dyn_cast<Constant>(Val))
520 AAResults *
AA,
bool *IsLoadCSE,
unsigned *NumScanedInst) {
521 if (MaxInstsToScan == 0)
522 MaxInstsToScan = ~0U;
527 while (ScanFrom != ScanBB->
begin()) {
541 if (MaxInstsToScan-- == 0)
547 AtLeastAtomic,
DL, IsLoadCSE))
552 Value *StorePtr =
SI->getPointerOperand()->stripPointerCasts();
557 if ((isa<AllocaInst>(StrippedPtr) || isa<GlobalVariable>(StrippedPtr)) &&
558 (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)) &&
559 StrippedPtr != StorePtr)
568 Loc.
Ptr, AccessTy,
SI->getPointerOperand(),
569 SI->getValueOperand()->getType(),
DL))
603 unsigned MaxInstsToScan) {
605 Value *StrippedPtr =
Load->getPointerOperand()->stripPointerCasts();
608 bool AtLeastAtomic =
Load->isAtomic();
610 if (!
Load->isUnordered())
619 if (Inst.isDebugOrPseudoInst())
622 if (MaxInstsToScan-- == 0)
626 AtLeastAtomic,
DL, IsLoadCSE);
630 if (Inst.mayWriteToMemory())
631 MustNotAliasInsts.push_back(&Inst);
648 Type *Ty = A->getType();
650 "values must have matching pointer types");
655 if (
auto *
C = dyn_cast<Constant>(
B)) {
658 APInt OneByte(
DL.getPointerTypeSizeInBits(Ty), 1);
659 return C->isNullValue() ||
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
This is an optimization pass for GlobalISel generic memory operations.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
A parsed version of the target data layout string in and methods for querying it.
InstListType::iterator iterator
Instruction iterators...
bool isPointerTy() const
True if this is an instance of PointerType.
const Value * Ptr
The address of the start of the location.
Represents a single loop in the control flow graph.
static bool isDereferenceableAndAlignedPointer(const Value *V, Align Alignment, const APInt &Size, const DataLayout &DL, const Instruction *CtxI, const DominatorTree *DT, const TargetLibraryInfo *TLI, SmallPtrSetImpl< const Value * > &Visited, unsigned MaxDepth)
Test if V is always a pointer to allocated and suitably aligned memory for a simple load or store.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static bool isKnownLE(const LinearPolySize &LHS, const LinearPolySize &RHS)
The main scalar evolution driver.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool canReplacePointersIfEqual(Value *A, Value *B, const DataLayout &DL, Instruction *CtxI)
Returns true if a pointer value A can be replace with another pointer value \B if they are deemed equ...
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
The instances of the Type class are immutable: once they are created, they are never changed.
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated.
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables.
Value * getPointerOperand()
Align getAlign() const
Return the alignment of the access that is being performed.
static Value * getAvailableLoadStore(Instruction *Inst, const Value *Ptr, Type *AccessTy, bool AtLeastAtomic, const DataLayout &DL, bool *IsLoadCSE)
LLVM Basic Block Representation.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
@ Available
We know the block is fully available. This is a fixpoint.
(vector float) vec_cmpeq(*A, *B) C
iterator begin()
Instruction iterator methods.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isDereferenceablePointer(const Value *V, Type *Ty, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if this is always a dereferenceable pointer.
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call, bool MustPreserveNullness)
This function returns call pointer argument that is considered the same by aliasing rules.
static LocationSize precise(uint64_t Value)
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
This struct is a compact representation of a valid (non-zero power of two) alignment.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL, const TargetLibraryInfo *TLI, ObjectSizeOpts Opts={})
Compute the size of the object pointed by Ptr.
Value * findAvailablePtrLoadStore(const MemoryLocation &Loc, Type *AccessTy, bool AtLeastAtomic, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan, AAResults *AA, bool *IsLoadCSE, unsigned *NumScanedInst)
Scan backwards to see if we have the value of the given pointer available locally within a small numb...
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
Attribute::AttrKind AttrKind
An instruction for storing to memory.
Represents calls to the gc.relocate intrinsic.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull, bool &CanBeFreed) const
Returns the number of bytes known to be dereferenceable for the pointer value.
static bool areNonOverlapSameBaseLoadAndStore(const Value *LoadPtr, Type *LoadTy, const Value *StorePtr, Type *StoreTy, const DataLayout &DL)
unsigned getSmallConstantMaxTripCount(const Loop *L)
Returns the upper bound of the loop trip count as a normal unsigned value.
static bool AreEquivalentAddressValues(const Value *A, const Value *B)
Test if A and B will obviously have the same value.
initializer< Ty > init(const Ty &Val)
bool getBoolValue() const
Convert APInt to a boolean value.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StandardInstrumentations SI(Debug, VerifyEach)
This class represents the LLVM 'select' instruction.
bool isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L, ScalarEvolution &SE, DominatorTree &DT)
Return true if we can prove that the given load (which is assumed to be within the specified loop) wo...
Class for arbitrary precision integers.
Constant * ConstantFoldLoadFromConst(Constant *C, Type *Ty, const APInt &Offset, const DataLayout &DL)
Extract value of C at the given Offset reinterpreted as Ty.
Type * getType() const
All values are typed, get the type of this value.
if(llvm_vc STREQUAL "") set(fake_version_inc "$
self_iterator getIterator()
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op.
Represent one information held inside an operand bundle of an llvm.assume.
Various options to control the behavior of getObjectSize.
An instruction for reading from memory.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
static const unsigned MaxDepth
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
Value * FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=DefMaxInstsToScan, AAResults *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 ...
BlockT * getHeader() const
Provides information about what library functions are available for the current target.
bool isDebugOrPseudoInst() const
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
This class represents a range of values.
bool canBeFreed() const
Return true if the memory object referred to by V can by freed in the scope for which the SSA value d...
ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
const BasicBlock * getParent() const
Align max(MaybeAlign Lhs, Align Rhs)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isSafeToLoadUnconditionally(Value *V, Align Alignment, APInt &Size, const DataLayout &DL, Instruction *ScanFrom=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if we know that executing a load from this value cannot trap.
bool isEmptySet() const
Return true if this set contains no members.
LLVM Value Representation.
Representation for a specific memory location.
cl::opt< unsigned > DefMaxInstsToScan
The default number of maximum instructions to scan in the block, used by FindAvailableLoadedValue().
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, Align Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
RetainedKnowledge getKnowledgeForValue(const Value *V, ArrayRef< Attribute::AttrKind > AttrKinds, AssumptionCache *AC=nullptr, function_ref< bool(RetainedKnowledge, Instruction *, const CallBase::BundleOpInfo *)> Filter=[](auto...) { return true;})
Return a valid Knowledge associated to the Value V if its Attribute kind is in AttrKinds and it match...