39 Align NewAlign = Fn(PtrOp, OldAlign, PrefAlign);
40 if (NewAlign > OldAlign) {
50 if (Const->ult(ActualAlign.
value())) {
56 I->replaceAllUsesWith(
I->getOperand(0));
62 if (
Log2(ActualAlign) >=
I->getType()->getScalarSizeInBits()) {
73 switch (
II->getIntrinsicID()) {
74 case Intrinsic::masked_load:
75 case Intrinsic::masked_store: {
76 unsigned PtrOpIdx =
II->getIntrinsicID() == Intrinsic::masked_load ? 0 : 1;
77 Value *PtrOp =
II->getArgOperand(PtrOpIdx);
78 Type *
Type =
II->getIntrinsicID() == Intrinsic::masked_load
80 :
II->getArgOperand(0)->getType();
82 Align OldAlign =
II->getParamAlign(PtrOpIdx).valueOrOne();
84 Align NewAlign = Fn(PtrOp, OldAlign, PrefAlign);
85 if (NewAlign <= OldAlign)
88 II->addParamAttr(PtrOpIdx,
102 DomTreeNode::const_iterator
Iter;
103 DomTreeNode::const_iterator
End;
120 if (PrefAlign > OldAlign)
121 return std::max(OldAlign,
139 auto InferFromBasePointer = [&](
Value *PtrOp,
Align LoadStoreAlign) {
140 APInt OffsetFromBase(
DL.getIndexTypeSizeInBits(PtrOp->
getType()), 0);
144 Align BasePointerAlign =
147 if (
auto BestAlign = BestBasePointerAligns.
lookup(PtrOp);
148 BestAlign !=
Align()) {
153 if (BestAlign > BasePointerAlign) {
154 Align BetterLoadStoreAlign =
156 return BetterLoadStoreAlign;
160 BestBasePointerAligns.
insert(PtrOp, BasePointerAlign);
161 return LoadStoreAlign;
165 std::list<AlignmentScope> Stack;
166 Stack.emplace_back(DT.
getRootNode(), BestBasePointerAligns);
167 while (!Stack.empty()) {
173 return std::max(InferFromKnownBits(
I, PtrOp),
174 InferFromBasePointer(PtrOp, OldAlign));
181 Stack.emplace_back(*Top.
Iter++, BestBasePointerAligns);
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool tryToImproveAlign(const DataLayout &DL, Instruction *I, function_ref< Align(Value *PtrOp, Align OldAlign, Align PrefAlign)> Fn)
bool inferAlignment(Function &F, AssumptionCache &AC, DominatorTree &DT)
ScopedHashTable< Value *, Align, DenseMapInfo< Value * >, BumpPtrAllocator > ScopedHT
uint64_t IntrinsicInst * II
Class for arbitrary precision integers.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
A function analysis which provides an AssumptionCache.
A cache of @llvm.assume calls within a function.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
LLVM Basic Block Representation.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
A wrapper class for inspecting calls to intrinsic functions.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void insert(const K &Key, const V &Val)
V lookup(const K &Key) const
ScopedHashTableScope< Value *, Align, DenseMapInfo< Value * >, BumpPtrAllocator > ScopeTy
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr, bool LookThroughIntToPtr=false) const
Accumulate the constant offset this value has compared to a base pointer.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
An efficient, type-erasing, non-owning reference to a callable.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
auto m_PtrToIntOrAddr(const OpTy &Op)
Matches PtrToInt or PtrToAddr.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
bool match(Val *V, const Pattern &P)
auto m_Value()
Match an arbitrary value and ignore it.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
Align getLoadStoreAlignment(const Value *I)
A helper function that returns the alignment of load or store instruction.
DomTreeNodeBase< BasicBlock > DomTreeNode
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI Align tryEnforceAlignment(Value *V, Align PrefAlign, const DataLayout &DL)
If the specified pointer points to an object that we control, try to modify the object's alignment to...
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Type * getLoadStoreType(const Value *I)
A helper function that returns the type of a load or store instruction.
void setLoadStoreAlignment(Value *I, Align NewAlign)
A helper function that set the alignment of load or store instruction.
unsigned Log2(Align A)
Returns the log2 of the alignment.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
DomTreeNode::const_iterator End
AlignmentScope(DomTreeNode *N, ScopedHT &Table)
DomTreeNode::const_iterator Iter
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
unsigned getBitWidth() const
Get the bit width of this value.