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");
60 dyn_cast<SCEVConstant>(DiffUnitsSCEV)) {
61 int64_t DiffUnits = ConstDUSCEV->getValue()->getSExtValue();
67 return cast<SCEVConstant>(AlignSCEV)->getValue()->getAlignValue();
71 uint64_t DiffUnitsAbs = std::abs(DiffUnits);
73 return Align(DiffUnitsAbs);
92 if (isa<SCEVCouldNotCompute>(DiffSCEV))
104 << *AlignSCEV <<
" and offset " << *OffSCEV
105 <<
" using diff " << *DiffSCEV <<
"\n");
109 return *NewAlignment;
112 if (
const SCEVAddRecExpr *DiffARSCEV = dyn_cast<SCEVAddRecExpr>(DiffSCEV)) {
120 const SCEV *DiffStartSCEV = DiffARSCEV->getStart();
121 const SCEV *DiffIncSCEV = DiffARSCEV->getStepRecurrence(*SE);
124 << *DiffStartSCEV <<
" and inc " << *DiffIncSCEV <<
"\n");
139 if (!NewAlignment || !NewIncAlignment)
142 const Align NewAlign = *NewAlignment;
143 const Align NewIncAlign = *NewIncAlignment;
144 if (NewAlign > NewIncAlign) {
149 if (NewIncAlign > NewAlign) {
154 assert(NewIncAlign == NewAlign);
166 const SCEV *&AlignSCEV,
167 const SCEV *&OffSCEV) {
173 AAPtr = AlignOB.
Inputs[0].get();
178 if (!isa<SCEVConstant>(AlignSCEV))
182 if (!cast<SCEVConstant>(AlignSCEV)->getAPInt().isPowerOf2())
185 if (AlignOB.
Inputs.size() == 3)
196 const SCEV *AlignSCEV, *OffSCEV;
202 if (isa<ConstantData>(AAPtr))
218 while (!WorkList.
empty()) {
220 if (
LoadInst *LI = dyn_cast<LoadInst>(J)) {
224 LI->getPointerOperand(),
SE);
225 if (NewAlignment > LI->getAlign()) {
226 LI->setAlignment(NewAlignment);
227 ++NumLoadAlignChanged;
229 }
else if (
StoreInst *SI = dyn_cast<StoreInst>(J)) {
233 SI->getPointerOperand(),
SE);
234 if (NewAlignment > SI->getAlign()) {
235 SI->setAlignment(NewAlignment);
236 ++NumStoreAlignChanged;
241 Align NewDestAlignment =
246 if (NewDestAlignment > *
MI->getDestAlign()) {
247 MI->setDestAlignment(NewDestAlignment);
248 ++NumMemIntAlignChanged;
254 Align NewSrcAlignment =
260 if (NewSrcAlignment > *MTI->getSourceAlign()) {
261 MTI->setSourceAlignment(NewSrcAlignment);
262 ++NumMemIntAlignChanged;
272 if (!Visited.
count(K))
286 bool Changed =
false;
289 CallInst *Call = cast<CallInst>(AssumeVH);
290 for (
unsigned Idx = 0;
Idx < Call->getNumOperandBundles();
Idx++)
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)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This is the interface for a simple mod/ref and alias analysis over globals.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
A container for analyses that lazily runs them and caches their results.
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.
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.
void preserveSet()
Mark an analysis set as preserved.
void 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.
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.
const SCEV * getURemExpr(const SCEV *LHS, const SCEV *RHS)
Represents an unsigned remainder expression based on unsigned division.
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
const SCEV * getNoopOrSignExtend(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
Type * getEffectiveSCEVType(Type *Ty) const
Return a type with the same bitwidth as the given type and which represents how SCEV will treat the g...
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS.
const SCEV * getTruncateOrZeroExtend(const SCEV *V, Type *Ty, unsigned Depth=0)
Return a SCEV corresponding to a conversion of the input value to the specified type.
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 IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
iterator_range< user_iterator > users()
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
This is an optimization pass for GlobalISel generic memory operations.
std::string DebugStr(const Align &A)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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 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.