34#define DEBUG_TYPE "alignment-from-assumptions"
38 "Number of loads changed by alignment assumptions");
40 "Number of stores changed by alignment assumptions");
42 "Number of memory intrinsics changed by alignment assumptions");
51 const SCEV *AlignSCEV,
56 LLVM_DEBUG(
dbgs() <<
"\talignment relative to " << *AlignSCEV <<
" is "
57 << *DiffUnitsSCEV <<
" (diff: " << *DiffSCEV <<
")\n");
61 int64_t DiffUnits = ConstDUSCEV->getValue()->getSExtValue();
71 uint64_t DiffUnitsAbs = std::abs(DiffUnits);
73 return Align(DiffUnitsAbs);
100 << *AlignSCEV <<
" and offset " << *OffSCEV
101 <<
" using diff " << *DiffSCEV <<
"\n");
105 return *NewAlignment;
116 const SCEV *DiffStartSCEV = DiffARSCEV->getStart();
117 const SCEV *DiffIncSCEV = DiffARSCEV->getStepRecurrence(*SE);
120 << *DiffStartSCEV <<
" and inc " << *DiffIncSCEV <<
"\n");
135 if (!NewAlignment || !NewIncAlignment)
138 const Align NewAlign = *NewAlignment;
139 const Align NewIncAlign = *NewIncAlignment;
140 if (NewAlign > NewIncAlign) {
145 if (NewIncAlign > NewAlign) {
150 assert(NewIncAlign == NewAlign);
162 const SCEV *&AlignSCEV,
163 const SCEV *&OffSCEV) {
169 AAPtr = AlignOB.
Inputs[0].get();
172 AlignSCEV =
SE->getSCEV(AlignOB.
Inputs[1].get());
173 AlignSCEV =
SE->getTruncateOrZeroExtend(AlignSCEV, Int64Ty);
181 if (AlignOB.
Inputs.size() == 3)
182 OffSCEV =
SE->getSCEV(AlignOB.
Inputs[2].get());
184 OffSCEV =
SE->getZero(Int64Ty);
185 OffSCEV =
SE->getTruncateOrZeroExtend(OffSCEV, Int64Ty);
192 const SCEV *AlignSCEV, *OffSCEV;
201 const SCEV *AASCEV =
SE->getSCEV(AAPtr);
215 while (!WorkList.
empty()) {
221 LI->getPointerOperand(),
SE);
222 if (NewAlignment > LI->getAlign()) {
223 LI->setAlignment(NewAlignment);
224 ++NumLoadAlignChanged;
230 SI->getPointerOperand(),
SE);
231 if (NewAlignment >
SI->getAlign()) {
232 SI->setAlignment(NewAlignment);
233 ++NumStoreAlignChanged;
238 Align NewDestAlignment =
243 if (NewDestAlignment > *
MI->getDestAlign()) {
244 MI->setDestAlignment(NewDestAlignment);
245 ++NumMemIntAlignChanged;
251 Align NewSrcAlignment =
257 if (NewSrcAlignment > *MTI->getSourceAlign()) {
258 MTI->setSourceAlignment(NewSrcAlignment);
259 ++NumMemIntAlignChanged;
268 for (
auto &U : J->
uses()) {
269 if (U->getType()->isPointerTy()) {
272 if (
SI &&
SI->getPointerOperandIndex() != U.getOperandNo())
274 if (!Visited.
count(K))
293 for (
unsigned Idx = 0; Idx <
Call->getNumOperandBundles(); Idx++)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static MaybeAlign getNewAlignmentDiff(const SCEV *DiffSCEV, const SCEV *AlignSCEV, ScalarEvolution *SE)
static Align getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV, const SCEV *OffSCEV, Value *Ptr, ScalarEvolution *SE)
This is the interface for a simple mod/ref and alias analysis over globals.
This file defines the SmallPtrSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
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.
MutableArrayRef< ResultElem > assumptions()
Access the list of assumption handles currently tracked for this function.
Represents analyses that only rely on functions' control flow.
This class represents a function call, abstracting a target machine's calling convention.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for reading from memory.
This is the common base class for memset/memcpy/memmove.
This class wraps the llvm.memcpy/memmove intrinsics.
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.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
This node represents a polynomial recurrence on the trip count of the specified loop.
This class represents a constant integer value.
This class represents an analyzed expression in the program.
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
Analysis pass that exposes the ScalarEvolution for a function.
The main scalar evolution driver.
LLVM_ABI const SCEV * getURemExpr(const SCEV *LHS, const SCEV *RHS)
Represents an unsigned remainder expression based on unsigned division.
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
LLVM_ABI const SCEV * getNoopOrSignExtend(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
LLVM_ABI const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
iterator_range< user_iterator > users()
LLVM_ABI const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
iterator_range< use_iterator > uses()
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
This struct is a compact representation of a valid (non-zero power of two) alignment.
bool extractAlignmentInfo(CallInst *I, unsigned Idx, Value *&AAPtr, const SCEV *&AlignSCEV, const SCEV *&OffSCEV)
bool processAssumption(CallInst *I, unsigned Idx)
bool runImpl(Function &F, AssumptionCache &AC, ScalarEvolution *SE_, DominatorTree *DT_)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
A lightweight accessor for an operand bundle meant to be passed around by value.
StringRef getTagName() const
Return the tag of this operand bundle as a string.