Go to the documentation of this file.
39 return BA >= Alignment && !(
Offset & (APAlign - 1));
56 if (!Visited.
insert(V).second)
63 if (
const SelectInst *Sel = dyn_cast<SelectInst>(V)) {
65 Size,
DL, CtxI, DT, TLI, Visited,
68 Size,
DL, CtxI, DT, TLI, Visited,
74 if (BC->getSrcTy()->isPointerTy())
76 BC->getOperand(0), Alignment,
Size,
DL, CtxI, DT, TLI,
80 bool CheckForNonNull, CheckForFreed;
102 V, {Attribute::Dereferenceable, Attribute::Alignment},
nullptr,
106 if (RK.
AttrKind == Attribute::Alignment)
108 if (RK.
AttrKind == Attribute::Dereferenceable)
123 const Value *Base =
GEP->getPointerOperand();
145 if (
const GCRelocateInst *RelocateInst = dyn_cast<GCRelocateInst>(V))
147 Alignment,
Size,
DL, CtxI, DT,
155 if (
const auto *Call = dyn_cast<CallBase>(V)) {
175 APInt KnownDerefBytes(
Size.getBitWidth(), ObjSize);
218 if (!Ty->
isSized() || isa<ScalableVectorType>(Ty))
227 const Align Alignment =
DL.getValueOrABITypeAlignment(MA, Ty);
229 DL.getTypeStoreSize(Ty));
263 if (isa<BinaryOperator>(A) || isa<CastInst>(A) || isa<PHINode>(A) ||
264 isa<GetElementPtrInst>(A))
266 if (cast<Instruction>(A)->isIdenticalToWhenDefined(BI))
280 DL.getTypeStoreSize(LI->
getType()).getFixedSize());
289 HeaderFirstNonPHI, &DT);
293 auto *AddRec = dyn_cast<SCEVAddRecExpr>(SE.
getSCEV(Ptr));
294 if (!AddRec || AddRec->getLoop() != L || !AddRec->isAffine())
296 auto* Step = dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(SE));
300 if (Step->getAPInt() != EltSize)
307 const APInt AccessSize = TC * EltSize;
309 auto *StartS = dyn_cast<SCEVUnknown>(AddRec->getStart());
313 Value *Base = StartS->getValue();
318 if (EltSize.urem(Alignment.
value()) != 0)
321 HeaderFirstNonPHI, &DT);
348 if (
Size.getBitWidth() > 64)
350 const uint64_t LoadSize =
Size.getZExtValue();
369 if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
370 !isa<DbgInfoIntrinsic>(BBI))
376 if (
LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
380 if (LI->isVolatile())
382 AccessedPtr = LI->getPointerOperand();
383 AccessedTy = LI->getType();
384 AccessedAlign = LI->getAlign();
385 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(BBI)) {
387 if (
SI->isVolatile())
389 AccessedPtr =
SI->getPointerOperand();
390 AccessedTy =
SI->getValueOperand()->getType();
391 AccessedAlign =
SI->getAlign();
395 if (AccessedAlign < Alignment)
399 if (AccessedPtr == V &&
400 LoadSize <=
DL.getTypeStoreSize(AccessedTy))
404 LoadSize <=
DL.getTypeStoreSize(AccessedTy))
427 cl::desc(
"Use this to specify the default maximum number of instructions "
428 "to scan backward from a given instruction, when searching for "
429 "available loaded value"));
434 unsigned MaxInstsToScan,
436 unsigned *NumScanedInst) {
438 if (!
Load->isUnordered())
443 ScanBB, ScanFrom, MaxInstsToScan, AA, IsLoad,
451 const Value *StorePtr,
457 DL, LoadOffset,
false);
459 DL, StoreOffset,
false);
460 if (LoadBase != StoreBase)
465 LoadOffset + LoadAccessSize.toRaw());
467 StoreOffset + StoreAccessSize.toRaw());
472 Type *AccessTy,
bool AtLeastAtomic,
477 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
480 if (LI->isAtomic() < AtLeastAtomic)
500 if (
SI->isAtomic() < AtLeastAtomic)
503 Value *StorePtr =
SI->getPointerOperand()->stripPointerCasts();
510 Value *Val =
SI->getValueOperand();
514 if (
auto *
C = dyn_cast<Constant>(Val))
524 AAResults *AA,
bool *IsLoadCSE,
unsigned *NumScanedInst) {
525 if (MaxInstsToScan == 0)
526 MaxInstsToScan = ~0U;
531 while (ScanFrom != ScanBB->
begin()) {
535 if (isa<DbgInfoIntrinsic>(Inst))
545 if (MaxInstsToScan-- == 0)
551 AtLeastAtomic,
DL, IsLoadCSE))
556 Value *StorePtr =
SI->getPointerOperand()->stripPointerCasts();
561 if ((isa<AllocaInst>(StrippedPtr) || isa<GlobalVariable>(StrippedPtr)) &&
562 (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)) &&
563 StrippedPtr != StorePtr)
572 Loc.
Ptr, AccessTy,
SI->getPointerOperand(),
573 SI->getValueOperand()->getType(),
DL))
607 unsigned MaxInstsToScan) {
609 Value *StrippedPtr =
Load->getPointerOperand()->stripPointerCasts();
612 bool AtLeastAtomic =
Load->isAtomic();
614 if (!
Load->isUnordered())
623 if (isa<DbgInfoIntrinsic>(&Inst))
626 if (MaxInstsToScan-- == 0)
630 AtLeastAtomic,
DL, IsLoadCSE);
634 if (Inst.mayWriteToMemory())
635 MustNotAliasInsts.push_back(&Inst);
652 Type *Ty = A->getType();
654 "values must have matching pointer types");
659 if (
auto *
C = dyn_cast<Constant>(
B)) {
662 APInt OneByte(
DL.getPointerTypeSizeInBits(Ty), 1);
663 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.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
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.
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, MaybeAlign 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.
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, 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,...
This class represents a conversion between pointers from one address space to another.
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.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
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.
Constant * ConstantFoldLoadThroughBitcast(Constant *C, Type *DestTy, const DataLayout &DL)
ConstantFoldLoadThroughBitcast - try to cast constant to destination type returning null if unsuccess...
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())
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.
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.
uint64_t value() const
This is a hole in the type system and should not be abused.
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.
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.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
Representation for a specific memory location.
cl::opt< unsigned > DefMaxInstsToScan
The default number of maximum instructions to scan in the block, used by FindAvailableLoadedValue().
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...