1 //===- LoopAccessAnalysis.cpp - Loop Access Analysis Implementation --------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // The implementation for the loop memory dependence that was originally
11 // developed for the loop vectorizer.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/LoopAccessAnalysis.h"
16 #include "llvm/Analysis/LoopInfo.h"
17 #include "llvm/Analysis/ScalarEvolutionExpander.h"
18 #include "llvm/Analysis/ValueTracking.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include "llvm/IR/Dominators.h"
21 #include "llvm/IR/IRBuilder.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Transforms/Utils/VectorUtils.h"
26 #define DEBUG_TYPE "loop-accesses"
28 void VectorizationReport::emitAnalysis(VectorizationReport &Message,
29 const Function *TheFunction,
31 const char *PassName) {
32 DebugLoc DL = TheLoop->getStartLoc();
33 if (Instruction *I = Message.getInstr())
34 DL = I->getDebugLoc();
35 emitOptimizationRemarkAnalysis(TheFunction->getContext(), PassName,
36 *TheFunction, DL, Message.str());
39 Value *llvm::stripIntegerCast(Value *V) {
40 if (CastInst *CI = dyn_cast<CastInst>(V))
41 if (CI->getOperand(0)->getType()->isIntegerTy())
42 return CI->getOperand(0);
46 const SCEV *llvm::replaceSymbolicStrideSCEV(ScalarEvolution *SE,
47 ValueToValueMap &PtrToStride,
48 Value *Ptr, Value *OrigPtr) {
50 const SCEV *OrigSCEV = SE->getSCEV(Ptr);
52 // If there is an entry in the map return the SCEV of the pointer with the
53 // symbolic stride replaced by one.
54 ValueToValueMap::iterator SI = PtrToStride.find(OrigPtr ? OrigPtr : Ptr);
55 if (SI != PtrToStride.end()) {
56 Value *StrideVal = SI->second;
59 StrideVal = stripIntegerCast(StrideVal);
61 // Replace symbolic stride by one.
62 Value *One = ConstantInt::get(StrideVal->getType(), 1);
63 ValueToValueMap RewriteMap;
64 RewriteMap[StrideVal] = One;
67 SCEVParameterRewriter::rewrite(OrigSCEV, *SE, RewriteMap, true);
68 DEBUG(dbgs() << "LAA: Replacing SCEV: " << *OrigSCEV << " by: " << *ByOne
73 // Otherwise, just return the SCEV of the original pointer.
74 return SE->getSCEV(Ptr);
77 void LoopAccessInfo::RuntimePointerCheck::insert(ScalarEvolution *SE, Loop *Lp,
78 Value *Ptr, bool WritePtr,
81 ValueToValueMap &Strides) {
82 // Get the stride replaced scev.
83 const SCEV *Sc = replaceSymbolicStrideSCEV(SE, Strides, Ptr);
84 const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Sc);
85 assert(AR && "Invalid addrec expression");
86 const SCEV *Ex = SE->getBackedgeTakenCount(Lp);
87 const SCEV *ScEnd = AR->evaluateAtIteration(Ex, *SE);
88 Pointers.push_back(Ptr);
89 Starts.push_back(AR->getStart());
90 Ends.push_back(ScEnd);
91 IsWritePtr.push_back(WritePtr);
92 DependencySetId.push_back(DepSetId);
93 AliasSetId.push_back(ASId);
96 bool LoopAccessInfo::RuntimePointerCheck::needsChecking(unsigned I,
98 // No need to check if two readonly pointers intersect.
99 if (!IsWritePtr[I] && !IsWritePtr[J])
102 // Only need to check pointers between two different dependency sets.
103 if (DependencySetId[I] == DependencySetId[J])
106 // Only need to check pointers in the same alias set.
107 if (AliasSetId[I] != AliasSetId[J])
114 /// \brief Analyses memory accesses in a loop.
116 /// Checks whether run time pointer checks are needed and builds sets for data
117 /// dependence checking.
118 class AccessAnalysis {
120 /// \brief Read or write access location.
121 typedef PointerIntPair<Value *, 1, bool> MemAccessInfo;
122 typedef SmallPtrSet<MemAccessInfo, 8> MemAccessInfoSet;
124 /// \brief Set of potential dependent memory accesses.
125 typedef EquivalenceClasses<MemAccessInfo> DepCandidates;
127 AccessAnalysis(const DataLayout *Dl, AliasAnalysis *AA, DepCandidates &DA) :
128 DL(Dl), AST(*AA), DepCands(DA), IsRTCheckNeeded(false) {}
130 /// \brief Register a load and whether it is only read from.
131 void addLoad(AliasAnalysis::Location &Loc, bool IsReadOnly) {
132 Value *Ptr = const_cast<Value*>(Loc.Ptr);
133 AST.add(Ptr, AliasAnalysis::UnknownSize, Loc.AATags);
134 Accesses.insert(MemAccessInfo(Ptr, false));
136 ReadOnlyPtr.insert(Ptr);
139 /// \brief Register a store.
140 void addStore(AliasAnalysis::Location &Loc) {
141 Value *Ptr = const_cast<Value*>(Loc.Ptr);
142 AST.add(Ptr, AliasAnalysis::UnknownSize, Loc.AATags);
143 Accesses.insert(MemAccessInfo(Ptr, true));
146 /// \brief Check whether we can check the pointers at runtime for
147 /// non-intersection.
148 bool canCheckPtrAtRT(LoopAccessInfo::RuntimePointerCheck &RtCheck,
149 unsigned &NumComparisons,
150 ScalarEvolution *SE, Loop *TheLoop,
151 ValueToValueMap &Strides,
152 bool ShouldCheckStride = false);
154 /// \brief Goes over all memory accesses, checks whether a RT check is needed
155 /// and builds sets of dependent accesses.
156 void buildDependenceSets() {
157 processMemAccesses();
160 bool isRTCheckNeeded() { return IsRTCheckNeeded; }
162 bool isDependencyCheckNeeded() { return !CheckDeps.empty(); }
163 void resetDepChecks() { CheckDeps.clear(); }
165 MemAccessInfoSet &getDependenciesToCheck() { return CheckDeps; }
168 typedef SetVector<MemAccessInfo> PtrAccessSet;
170 /// \brief Go over all memory access and check whether runtime pointer checks
171 /// are needed /// and build sets of dependency check candidates.
172 void processMemAccesses();
174 /// Set of all accesses.
175 PtrAccessSet Accesses;
177 /// Set of accesses that need a further dependence check.
178 MemAccessInfoSet CheckDeps;
180 /// Set of pointers that are read only.
181 SmallPtrSet<Value*, 16> ReadOnlyPtr;
183 const DataLayout *DL;
185 /// An alias set tracker to partition the access set by underlying object and
186 //intrinsic property (such as TBAA metadata).
189 /// Sets of potentially dependent accesses - members of one set share an
190 /// underlying pointer. The set "CheckDeps" identfies which sets really need a
191 /// dependence check.
192 DepCandidates &DepCands;
194 bool IsRTCheckNeeded;
197 } // end anonymous namespace
199 /// \brief Check whether a pointer can participate in a runtime bounds check.
200 static bool hasComputableBounds(ScalarEvolution *SE, ValueToValueMap &Strides,
202 const SCEV *PtrScev = replaceSymbolicStrideSCEV(SE, Strides, Ptr);
203 const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev);
207 return AR->isAffine();
210 /// \brief Check the stride of the pointer and ensure that it does not wrap in
211 /// the address space.
212 static int isStridedPtr(ScalarEvolution *SE, const DataLayout *DL, Value *Ptr,
213 const Loop *Lp, ValueToValueMap &StridesMap);
215 bool AccessAnalysis::canCheckPtrAtRT(
216 LoopAccessInfo::RuntimePointerCheck &RtCheck,
217 unsigned &NumComparisons, ScalarEvolution *SE, Loop *TheLoop,
218 ValueToValueMap &StridesMap, bool ShouldCheckStride) {
219 // Find pointers with computable bounds. We are going to use this information
220 // to place a runtime bound check.
223 bool IsDepCheckNeeded = isDependencyCheckNeeded();
226 // We assign a consecutive id to access from different alias sets.
227 // Accesses between different groups doesn't need to be checked.
229 for (auto &AS : AST) {
230 unsigned NumReadPtrChecks = 0;
231 unsigned NumWritePtrChecks = 0;
233 // We assign consecutive id to access from different dependence sets.
234 // Accesses within the same set don't need a runtime check.
235 unsigned RunningDepId = 1;
236 DenseMap<Value *, unsigned> DepSetId;
239 Value *Ptr = A.getValue();
240 bool IsWrite = Accesses.count(MemAccessInfo(Ptr, true));
241 MemAccessInfo Access(Ptr, IsWrite);
248 if (hasComputableBounds(SE, StridesMap, Ptr) &&
249 // When we run after a failing dependency check we have to make sure we
250 // don't have wrapping pointers.
251 (!ShouldCheckStride ||
252 isStridedPtr(SE, DL, Ptr, TheLoop, StridesMap) == 1)) {
253 // The id of the dependence set.
256 if (IsDepCheckNeeded) {
257 Value *Leader = DepCands.getLeaderValue(Access).getPointer();
258 unsigned &LeaderId = DepSetId[Leader];
260 LeaderId = RunningDepId++;
263 // Each access has its own dependence set.
264 DepId = RunningDepId++;
266 RtCheck.insert(SE, TheLoop, Ptr, IsWrite, DepId, ASId, StridesMap);
268 DEBUG(dbgs() << "LAA: Found a runtime check ptr:" << *Ptr << '\n');
274 if (IsDepCheckNeeded && CanDoRT && RunningDepId == 2)
275 NumComparisons += 0; // Only one dependence set.
277 NumComparisons += (NumWritePtrChecks * (NumReadPtrChecks +
278 NumWritePtrChecks - 1));
284 // If the pointers that we would use for the bounds comparison have different
285 // address spaces, assume the values aren't directly comparable, so we can't
286 // use them for the runtime check. We also have to assume they could
287 // overlap. In the future there should be metadata for whether address spaces
289 unsigned NumPointers = RtCheck.Pointers.size();
290 for (unsigned i = 0; i < NumPointers; ++i) {
291 for (unsigned j = i + 1; j < NumPointers; ++j) {
292 // Only need to check pointers between two different dependency sets.
293 if (RtCheck.DependencySetId[i] == RtCheck.DependencySetId[j])
295 // Only need to check pointers in the same alias set.
296 if (RtCheck.AliasSetId[i] != RtCheck.AliasSetId[j])
299 Value *PtrI = RtCheck.Pointers[i];
300 Value *PtrJ = RtCheck.Pointers[j];
302 unsigned ASi = PtrI->getType()->getPointerAddressSpace();
303 unsigned ASj = PtrJ->getType()->getPointerAddressSpace();
305 DEBUG(dbgs() << "LAA: Runtime check would require comparison between"
306 " different address spaces\n");
315 void AccessAnalysis::processMemAccesses() {
316 // We process the set twice: first we process read-write pointers, last we
317 // process read-only pointers. This allows us to skip dependence tests for
318 // read-only pointers.
320 DEBUG(dbgs() << "LAA: Processing memory accesses...\n");
321 DEBUG(dbgs() << " AST: "; AST.dump());
322 DEBUG(dbgs() << "LAA: Accesses:\n");
324 for (auto A : Accesses)
325 dbgs() << "\t" << *A.getPointer() << " (" <<
326 (A.getInt() ? "write" : (ReadOnlyPtr.count(A.getPointer()) ?
327 "read-only" : "read")) << ")\n";
330 // The AliasSetTracker has nicely partitioned our pointers by metadata
331 // compatibility and potential for underlying-object overlap. As a result, we
332 // only need to check for potential pointer dependencies within each alias
334 for (auto &AS : AST) {
335 // Note that both the alias-set tracker and the alias sets themselves used
336 // linked lists internally and so the iteration order here is deterministic
337 // (matching the original instruction order within each set).
339 bool SetHasWrite = false;
341 // Map of pointers to last access encountered.
342 typedef DenseMap<Value*, MemAccessInfo> UnderlyingObjToAccessMap;
343 UnderlyingObjToAccessMap ObjToLastAccess;
345 // Set of access to check after all writes have been processed.
346 PtrAccessSet DeferredAccesses;
348 // Iterate over each alias set twice, once to process read/write pointers,
349 // and then to process read-only pointers.
350 for (int SetIteration = 0; SetIteration < 2; ++SetIteration) {
351 bool UseDeferred = SetIteration > 0;
352 PtrAccessSet &S = UseDeferred ? DeferredAccesses : Accesses;
355 Value *Ptr = AV.getValue();
357 // For a single memory access in AliasSetTracker, Accesses may contain
358 // both read and write, and they both need to be handled for CheckDeps.
360 if (AC.getPointer() != Ptr)
363 bool IsWrite = AC.getInt();
365 // If we're using the deferred access set, then it contains only
367 bool IsReadOnlyPtr = ReadOnlyPtr.count(Ptr) && !IsWrite;
368 if (UseDeferred && !IsReadOnlyPtr)
370 // Otherwise, the pointer must be in the PtrAccessSet, either as a
372 assert(((IsReadOnlyPtr && UseDeferred) || IsWrite ||
373 S.count(MemAccessInfo(Ptr, false))) &&
374 "Alias-set pointer not in the access set?");
376 MemAccessInfo Access(Ptr, IsWrite);
377 DepCands.insert(Access);
379 // Memorize read-only pointers for later processing and skip them in
380 // the first round (they need to be checked after we have seen all
381 // write pointers). Note: we also mark pointer that are not
382 // consecutive as "read-only" pointers (so that we check
383 // "a[b[i]] +="). Hence, we need the second check for "!IsWrite".
384 if (!UseDeferred && IsReadOnlyPtr) {
385 DeferredAccesses.insert(Access);
389 // If this is a write - check other reads and writes for conflicts. If
390 // this is a read only check other writes for conflicts (but only if
391 // there is no other write to the ptr - this is an optimization to
392 // catch "a[i] = a[i] + " without having to do a dependence check).
393 if ((IsWrite || IsReadOnlyPtr) && SetHasWrite) {
394 CheckDeps.insert(Access);
395 IsRTCheckNeeded = true;
401 // Create sets of pointers connected by a shared alias set and
402 // underlying object.
403 typedef SmallVector<Value *, 16> ValueVector;
404 ValueVector TempObjects;
405 GetUnderlyingObjects(Ptr, TempObjects, DL);
406 for (Value *UnderlyingObj : TempObjects) {
407 UnderlyingObjToAccessMap::iterator Prev =
408 ObjToLastAccess.find(UnderlyingObj);
409 if (Prev != ObjToLastAccess.end())
410 DepCands.unionSets(Access, Prev->second);
412 ObjToLastAccess[UnderlyingObj] = Access;
421 /// \brief Checks memory dependences among accesses to the same underlying
422 /// object to determine whether there vectorization is legal or not (and at
423 /// which vectorization factor).
425 /// This class works under the assumption that we already checked that memory
426 /// locations with different underlying pointers are "must-not alias".
427 /// We use the ScalarEvolution framework to symbolically evalutate access
428 /// functions pairs. Since we currently don't restructure the loop we can rely
429 /// on the program order of memory accesses to determine their safety.
430 /// At the moment we will only deem accesses as safe for:
431 /// * A negative constant distance assuming program order.
433 /// Safe: tmp = a[i + 1]; OR a[i + 1] = x;
434 /// a[i] = tmp; y = a[i];
436 /// The latter case is safe because later checks guarantuee that there can't
437 /// be a cycle through a phi node (that is, we check that "x" and "y" is not
438 /// the same variable: a header phi can only be an induction or a reduction, a
439 /// reduction can't have a memory sink, an induction can't have a memory
440 /// source). This is important and must not be violated (or we have to
441 /// resort to checking for cycles through memory).
443 /// * A positive constant distance assuming program order that is bigger
444 /// than the biggest memory access.
446 /// tmp = a[i] OR b[i] = x
447 /// a[i+2] = tmp y = b[i+2];
449 /// Safe distance: 2 x sizeof(a[0]), and 2 x sizeof(b[0]), respectively.
451 /// * Zero distances and all accesses have the same size.
453 class MemoryDepChecker {
455 typedef PointerIntPair<Value *, 1, bool> MemAccessInfo;
456 typedef SmallPtrSet<MemAccessInfo, 8> MemAccessInfoSet;
458 MemoryDepChecker(ScalarEvolution *Se, const DataLayout *Dl, const Loop *L)
459 : SE(Se), DL(Dl), InnermostLoop(L), AccessIdx(0),
460 ShouldRetryWithRuntimeCheck(false) {}
462 /// \brief Register the location (instructions are given increasing numbers)
463 /// of a write access.
464 void addAccess(StoreInst *SI) {
465 Value *Ptr = SI->getPointerOperand();
466 Accesses[MemAccessInfo(Ptr, true)].push_back(AccessIdx);
467 InstMap.push_back(SI);
471 /// \brief Register the location (instructions are given increasing numbers)
472 /// of a write access.
473 void addAccess(LoadInst *LI) {
474 Value *Ptr = LI->getPointerOperand();
475 Accesses[MemAccessInfo(Ptr, false)].push_back(AccessIdx);
476 InstMap.push_back(LI);
480 /// \brief Check whether the dependencies between the accesses are safe.
482 /// Only checks sets with elements in \p CheckDeps.
483 bool areDepsSafe(AccessAnalysis::DepCandidates &AccessSets,
484 MemAccessInfoSet &CheckDeps, ValueToValueMap &Strides);
486 /// \brief The maximum number of bytes of a vector register we can vectorize
487 /// the accesses safely with.
488 unsigned getMaxSafeDepDistBytes() { return MaxSafeDepDistBytes; }
490 /// \brief In same cases when the dependency check fails we can still
491 /// vectorize the loop with a dynamic array access check.
492 bool shouldRetryWithRuntimeCheck() { return ShouldRetryWithRuntimeCheck; }
496 const DataLayout *DL;
497 const Loop *InnermostLoop;
499 /// \brief Maps access locations (ptr, read/write) to program order.
500 DenseMap<MemAccessInfo, std::vector<unsigned> > Accesses;
502 /// \brief Memory access instructions in program order.
503 SmallVector<Instruction *, 16> InstMap;
505 /// \brief The program order index to be used for the next instruction.
508 // We can access this many bytes in parallel safely.
509 unsigned MaxSafeDepDistBytes;
511 /// \brief If we see a non-constant dependence distance we can still try to
512 /// vectorize this loop with runtime checks.
513 bool ShouldRetryWithRuntimeCheck;
515 /// \brief Check whether there is a plausible dependence between the two
518 /// Access \p A must happen before \p B in program order. The two indices
519 /// identify the index into the program order map.
521 /// This function checks whether there is a plausible dependence (or the
522 /// absence of such can't be proved) between the two accesses. If there is a
523 /// plausible dependence but the dependence distance is bigger than one
524 /// element access it records this distance in \p MaxSafeDepDistBytes (if this
525 /// distance is smaller than any other distance encountered so far).
526 /// Otherwise, this function returns true signaling a possible dependence.
527 bool isDependent(const MemAccessInfo &A, unsigned AIdx,
528 const MemAccessInfo &B, unsigned BIdx,
529 ValueToValueMap &Strides);
531 /// \brief Check whether the data dependence could prevent store-load
533 bool couldPreventStoreLoadForward(unsigned Distance, unsigned TypeByteSize);
536 } // end anonymous namespace
538 static bool isInBoundsGep(Value *Ptr) {
539 if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr))
540 return GEP->isInBounds();
544 /// \brief Check whether the access through \p Ptr has a constant stride.
545 static int isStridedPtr(ScalarEvolution *SE, const DataLayout *DL, Value *Ptr,
546 const Loop *Lp, ValueToValueMap &StridesMap) {
547 const Type *Ty = Ptr->getType();
548 assert(Ty->isPointerTy() && "Unexpected non-ptr");
550 // Make sure that the pointer does not point to aggregate types.
551 const PointerType *PtrTy = cast<PointerType>(Ty);
552 if (PtrTy->getElementType()->isAggregateType()) {
553 DEBUG(dbgs() << "LAA: Bad stride - Not a pointer to a scalar type"
558 const SCEV *PtrScev = replaceSymbolicStrideSCEV(SE, StridesMap, Ptr);
560 const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev);
562 DEBUG(dbgs() << "LAA: Bad stride - Not an AddRecExpr pointer "
563 << *Ptr << " SCEV: " << *PtrScev << "\n");
567 // The accesss function must stride over the innermost loop.
568 if (Lp != AR->getLoop()) {
569 DEBUG(dbgs() << "LAA: Bad stride - Not striding over innermost loop " <<
570 *Ptr << " SCEV: " << *PtrScev << "\n");
573 // The address calculation must not wrap. Otherwise, a dependence could be
575 // An inbounds getelementptr that is a AddRec with a unit stride
576 // cannot wrap per definition. The unit stride requirement is checked later.
577 // An getelementptr without an inbounds attribute and unit stride would have
578 // to access the pointer value "0" which is undefined behavior in address
579 // space 0, therefore we can also vectorize this case.
580 bool IsInBoundsGEP = isInBoundsGep(Ptr);
581 bool IsNoWrapAddRec = AR->getNoWrapFlags(SCEV::NoWrapMask);
582 bool IsInAddressSpaceZero = PtrTy->getAddressSpace() == 0;
583 if (!IsNoWrapAddRec && !IsInBoundsGEP && !IsInAddressSpaceZero) {
584 DEBUG(dbgs() << "LAA: Bad stride - Pointer may wrap in the address space "
585 << *Ptr << " SCEV: " << *PtrScev << "\n");
589 // Check the step is constant.
590 const SCEV *Step = AR->getStepRecurrence(*SE);
592 // Calculate the pointer stride and check if it is consecutive.
593 const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
595 DEBUG(dbgs() << "LAA: Bad stride - Not a constant strided " << *Ptr <<
596 " SCEV: " << *PtrScev << "\n");
600 int64_t Size = DL->getTypeAllocSize(PtrTy->getElementType());
601 const APInt &APStepVal = C->getValue()->getValue();
603 // Huge step value - give up.
604 if (APStepVal.getBitWidth() > 64)
607 int64_t StepVal = APStepVal.getSExtValue();
610 int64_t Stride = StepVal / Size;
611 int64_t Rem = StepVal % Size;
615 // If the SCEV could wrap but we have an inbounds gep with a unit stride we
616 // know we can't "wrap around the address space". In case of address space
617 // zero we know that this won't happen without triggering undefined behavior.
618 if (!IsNoWrapAddRec && (IsInBoundsGEP || IsInAddressSpaceZero) &&
619 Stride != 1 && Stride != -1)
625 bool MemoryDepChecker::couldPreventStoreLoadForward(unsigned Distance,
626 unsigned TypeByteSize) {
627 // If loads occur at a distance that is not a multiple of a feasible vector
628 // factor store-load forwarding does not take place.
629 // Positive dependences might cause troubles because vectorizing them might
630 // prevent store-load forwarding making vectorized code run a lot slower.
631 // a[i] = a[i-3] ^ a[i-8];
632 // The stores to a[i:i+1] don't align with the stores to a[i-3:i-2] and
633 // hence on your typical architecture store-load forwarding does not take
634 // place. Vectorizing in such cases does not make sense.
635 // Store-load forwarding distance.
636 const unsigned NumCyclesForStoreLoadThroughMemory = 8*TypeByteSize;
637 // Maximum vector factor.
638 unsigned MaxVFWithoutSLForwardIssues =
639 VectorizerParams::MaxVectorWidth * TypeByteSize;
640 if(MaxSafeDepDistBytes < MaxVFWithoutSLForwardIssues)
641 MaxVFWithoutSLForwardIssues = MaxSafeDepDistBytes;
643 for (unsigned vf = 2*TypeByteSize; vf <= MaxVFWithoutSLForwardIssues;
645 if (Distance % vf && Distance / vf < NumCyclesForStoreLoadThroughMemory) {
646 MaxVFWithoutSLForwardIssues = (vf >>=1);
651 if (MaxVFWithoutSLForwardIssues< 2*TypeByteSize) {
652 DEBUG(dbgs() << "LAA: Distance " << Distance <<
653 " that could cause a store-load forwarding conflict\n");
657 if (MaxVFWithoutSLForwardIssues < MaxSafeDepDistBytes &&
658 MaxVFWithoutSLForwardIssues !=
659 VectorizerParams::MaxVectorWidth * TypeByteSize)
660 MaxSafeDepDistBytes = MaxVFWithoutSLForwardIssues;
664 bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
665 const MemAccessInfo &B, unsigned BIdx,
666 ValueToValueMap &Strides) {
667 assert (AIdx < BIdx && "Must pass arguments in program order");
669 Value *APtr = A.getPointer();
670 Value *BPtr = B.getPointer();
671 bool AIsWrite = A.getInt();
672 bool BIsWrite = B.getInt();
674 // Two reads are independent.
675 if (!AIsWrite && !BIsWrite)
678 // We cannot check pointers in different address spaces.
679 if (APtr->getType()->getPointerAddressSpace() !=
680 BPtr->getType()->getPointerAddressSpace())
683 const SCEV *AScev = replaceSymbolicStrideSCEV(SE, Strides, APtr);
684 const SCEV *BScev = replaceSymbolicStrideSCEV(SE, Strides, BPtr);
686 int StrideAPtr = isStridedPtr(SE, DL, APtr, InnermostLoop, Strides);
687 int StrideBPtr = isStridedPtr(SE, DL, BPtr, InnermostLoop, Strides);
689 const SCEV *Src = AScev;
690 const SCEV *Sink = BScev;
692 // If the induction step is negative we have to invert source and sink of the
694 if (StrideAPtr < 0) {
697 std::swap(APtr, BPtr);
698 std::swap(Src, Sink);
699 std::swap(AIsWrite, BIsWrite);
700 std::swap(AIdx, BIdx);
701 std::swap(StrideAPtr, StrideBPtr);
704 const SCEV *Dist = SE->getMinusSCEV(Sink, Src);
706 DEBUG(dbgs() << "LAA: Src Scev: " << *Src << "Sink Scev: " << *Sink
707 << "(Induction step: " << StrideAPtr << ")\n");
708 DEBUG(dbgs() << "LAA: Distance for " << *InstMap[AIdx] << " to "
709 << *InstMap[BIdx] << ": " << *Dist << "\n");
711 // Need consecutive accesses. We don't want to vectorize
712 // "A[B[i]] += ..." and similar code or pointer arithmetic that could wrap in
713 // the address space.
714 if (!StrideAPtr || !StrideBPtr || StrideAPtr != StrideBPtr){
715 DEBUG(dbgs() << "Non-consecutive pointer access\n");
719 const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist);
721 DEBUG(dbgs() << "LAA: Dependence because of non-constant distance\n");
722 ShouldRetryWithRuntimeCheck = true;
726 Type *ATy = APtr->getType()->getPointerElementType();
727 Type *BTy = BPtr->getType()->getPointerElementType();
728 unsigned TypeByteSize = DL->getTypeAllocSize(ATy);
730 // Negative distances are not plausible dependencies.
731 const APInt &Val = C->getValue()->getValue();
732 if (Val.isNegative()) {
733 bool IsTrueDataDependence = (AIsWrite && !BIsWrite);
734 if (IsTrueDataDependence &&
735 (couldPreventStoreLoadForward(Val.abs().getZExtValue(), TypeByteSize) ||
739 DEBUG(dbgs() << "LAA: Dependence is negative: NoDep\n");
743 // Write to the same location with the same size.
744 // Could be improved to assert type sizes are the same (i32 == float, etc).
748 DEBUG(dbgs() << "LAA: Zero dependence difference but different types\n");
752 assert(Val.isStrictlyPositive() && "Expect a positive value");
754 // Positive distance bigger than max vectorization factor.
757 "LAA: ReadWrite-Write positive dependency with different types\n");
761 unsigned Distance = (unsigned) Val.getZExtValue();
763 // Bail out early if passed-in parameters make vectorization not feasible.
764 unsigned ForcedFactor = (VectorizerParams::VectorizationFactor ?
765 VectorizerParams::VectorizationFactor : 1);
766 unsigned ForcedUnroll = (VectorizerParams::VectorizationInterleave ?
767 VectorizerParams::VectorizationInterleave : 1);
769 // The distance must be bigger than the size needed for a vectorized version
770 // of the operation and the size of the vectorized operation must not be
771 // bigger than the currrent maximum size.
772 if (Distance < 2*TypeByteSize ||
773 2*TypeByteSize > MaxSafeDepDistBytes ||
774 Distance < TypeByteSize * ForcedUnroll * ForcedFactor) {
775 DEBUG(dbgs() << "LAA: Failure because of Positive distance "
776 << Val.getSExtValue() << '\n');
780 MaxSafeDepDistBytes = Distance < MaxSafeDepDistBytes ?
781 Distance : MaxSafeDepDistBytes;
783 bool IsTrueDataDependence = (!AIsWrite && BIsWrite);
784 if (IsTrueDataDependence &&
785 couldPreventStoreLoadForward(Distance, TypeByteSize))
788 DEBUG(dbgs() << "LAA: Positive distance " << Val.getSExtValue() <<
789 " with max VF = " << MaxSafeDepDistBytes / TypeByteSize << '\n');
794 bool MemoryDepChecker::areDepsSafe(AccessAnalysis::DepCandidates &AccessSets,
795 MemAccessInfoSet &CheckDeps,
796 ValueToValueMap &Strides) {
798 MaxSafeDepDistBytes = -1U;
799 while (!CheckDeps.empty()) {
800 MemAccessInfo CurAccess = *CheckDeps.begin();
802 // Get the relevant memory access set.
803 EquivalenceClasses<MemAccessInfo>::iterator I =
804 AccessSets.findValue(AccessSets.getLeaderValue(CurAccess));
806 // Check accesses within this set.
807 EquivalenceClasses<MemAccessInfo>::member_iterator AI, AE;
808 AI = AccessSets.member_begin(I), AE = AccessSets.member_end();
810 // Check every access pair.
812 CheckDeps.erase(*AI);
813 EquivalenceClasses<MemAccessInfo>::member_iterator OI = std::next(AI);
815 // Check every accessing instruction pair in program order.
816 for (std::vector<unsigned>::iterator I1 = Accesses[*AI].begin(),
817 I1E = Accesses[*AI].end(); I1 != I1E; ++I1)
818 for (std::vector<unsigned>::iterator I2 = Accesses[*OI].begin(),
819 I2E = Accesses[*OI].end(); I2 != I2E; ++I2) {
820 if (*I1 < *I2 && isDependent(*AI, *I1, *OI, *I2, Strides))
822 if (*I2 < *I1 && isDependent(*OI, *I2, *AI, *I1, Strides))
833 bool LoopAccessInfo::canAnalyzeLoop() {
834 // We can only analyze innermost loops.
835 if (!TheLoop->empty()) {
836 emitAnalysis(VectorizationReport() << "loop is not the innermost loop");
840 // We must have a single backedge.
841 if (TheLoop->getNumBackEdges() != 1) {
843 VectorizationReport() <<
844 "loop control flow is not understood by analyzer");
848 // We must have a single exiting block.
849 if (!TheLoop->getExitingBlock()) {
851 VectorizationReport() <<
852 "loop control flow is not understood by analyzer");
856 // We only handle bottom-tested loops, i.e. loop in which the condition is
857 // checked at the end of each iteration. With that we can assume that all
858 // instructions in the loop are executed the same number of times.
859 if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) {
861 VectorizationReport() <<
862 "loop control flow is not understood by analyzer");
866 // We need to have a loop header.
867 DEBUG(dbgs() << "LAA: Found a loop: " <<
868 TheLoop->getHeader()->getName() << '\n');
870 // ScalarEvolution needs to be able to find the exit count.
871 const SCEV *ExitCount = SE->getBackedgeTakenCount(TheLoop);
872 if (ExitCount == SE->getCouldNotCompute()) {
873 emitAnalysis(VectorizationReport() <<
874 "could not determine number of loop iterations");
875 DEBUG(dbgs() << "LAA: SCEV could not compute the loop exit count.\n");
882 void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
884 typedef SmallVector<Value*, 16> ValueVector;
885 typedef SmallPtrSet<Value*, 16> ValueSet;
887 // Holds the Load and Store *instructions*.
891 // Holds all the different accesses in the loop.
892 unsigned NumReads = 0;
893 unsigned NumReadWrites = 0;
895 PtrRtCheck.Pointers.clear();
896 PtrRtCheck.Need = false;
898 const bool IsAnnotatedParallel = TheLoop->isAnnotatedParallel();
899 MemoryDepChecker DepChecker(SE, DL, TheLoop);
902 for (Loop::block_iterator bb = TheLoop->block_begin(),
903 be = TheLoop->block_end(); bb != be; ++bb) {
905 // Scan the BB and collect legal loads and stores.
906 for (BasicBlock::iterator it = (*bb)->begin(), e = (*bb)->end(); it != e;
909 // If this is a load, save it. If this instruction can read from memory
910 // but is not a load, then we quit. Notice that we don't handle function
911 // calls that read or write.
912 if (it->mayReadFromMemory()) {
913 // Many math library functions read the rounding mode. We will only
914 // vectorize a loop if it contains known function calls that don't set
915 // the flag. Therefore, it is safe to ignore this read from memory.
916 CallInst *Call = dyn_cast<CallInst>(it);
917 if (Call && getIntrinsicIDForCall(Call, TLI))
920 LoadInst *Ld = dyn_cast<LoadInst>(it);
921 if (!Ld || (!Ld->isSimple() && !IsAnnotatedParallel)) {
922 emitAnalysis(VectorizationReport(Ld)
923 << "read with atomic ordering or volatile read");
924 DEBUG(dbgs() << "LAA: Found a non-simple load.\n");
930 DepChecker.addAccess(Ld);
934 // Save 'store' instructions. Abort if other instructions write to memory.
935 if (it->mayWriteToMemory()) {
936 StoreInst *St = dyn_cast<StoreInst>(it);
938 emitAnalysis(VectorizationReport(it) <<
939 "instruction cannot be vectorized");
943 if (!St->isSimple() && !IsAnnotatedParallel) {
944 emitAnalysis(VectorizationReport(St)
945 << "write with atomic ordering or volatile write");
946 DEBUG(dbgs() << "LAA: Found a non-simple store.\n");
951 Stores.push_back(St);
952 DepChecker.addAccess(St);
957 // Now we have two lists that hold the loads and the stores.
958 // Next, we find the pointers that they use.
960 // Check if we see any stores. If there are no stores, then we don't
961 // care if the pointers are *restrict*.
962 if (!Stores.size()) {
963 DEBUG(dbgs() << "LAA: Found a read-only loop!\n");
968 AccessAnalysis::DepCandidates DependentAccesses;
969 AccessAnalysis Accesses(DL, AA, DependentAccesses);
971 // Holds the analyzed pointers. We don't want to call GetUnderlyingObjects
972 // multiple times on the same object. If the ptr is accessed twice, once
973 // for read and once for write, it will only appear once (on the write
974 // list). This is okay, since we are going to check for conflicts between
975 // writes and between reads and writes, but not between reads and reads.
978 ValueVector::iterator I, IE;
979 for (I = Stores.begin(), IE = Stores.end(); I != IE; ++I) {
980 StoreInst *ST = cast<StoreInst>(*I);
981 Value* Ptr = ST->getPointerOperand();
983 if (isUniform(Ptr)) {
985 VectorizationReport(ST)
986 << "write to a loop invariant address could not be vectorized");
987 DEBUG(dbgs() << "LAA: We don't allow storing to uniform addresses\n");
992 // If we did *not* see this pointer before, insert it to the read-write
993 // list. At this phase it is only a 'write' list.
994 if (Seen.insert(Ptr).second) {
997 AliasAnalysis::Location Loc = AA->getLocation(ST);
998 // The TBAA metadata could have a control dependency on the predication
999 // condition, so we cannot rely on it when determining whether or not we
1000 // need runtime pointer checks.
1001 if (blockNeedsPredication(ST->getParent(), TheLoop, DT))
1002 Loc.AATags.TBAA = nullptr;
1004 Accesses.addStore(Loc);
1008 if (IsAnnotatedParallel) {
1010 << "LAA: A loop annotated parallel, ignore memory dependency "
1016 for (I = Loads.begin(), IE = Loads.end(); I != IE; ++I) {
1017 LoadInst *LD = cast<LoadInst>(*I);
1018 Value* Ptr = LD->getPointerOperand();
1019 // If we did *not* see this pointer before, insert it to the
1020 // read list. If we *did* see it before, then it is already in
1021 // the read-write list. This allows us to vectorize expressions
1022 // such as A[i] += x; Because the address of A[i] is a read-write
1023 // pointer. This only works if the index of A[i] is consecutive.
1024 // If the address of i is unknown (for example A[B[i]]) then we may
1025 // read a few words, modify, and write a few words, and some of the
1026 // words may be written to the same address.
1027 bool IsReadOnlyPtr = false;
1028 if (Seen.insert(Ptr).second ||
1029 !isStridedPtr(SE, DL, Ptr, TheLoop, Strides)) {
1031 IsReadOnlyPtr = true;
1034 AliasAnalysis::Location Loc = AA->getLocation(LD);
1035 // The TBAA metadata could have a control dependency on the predication
1036 // condition, so we cannot rely on it when determining whether or not we
1037 // need runtime pointer checks.
1038 if (blockNeedsPredication(LD->getParent(), TheLoop, DT))
1039 Loc.AATags.TBAA = nullptr;
1041 Accesses.addLoad(Loc, IsReadOnlyPtr);
1044 // If we write (or read-write) to a single destination and there are no
1045 // other reads in this loop then is it safe to vectorize.
1046 if (NumReadWrites == 1 && NumReads == 0) {
1047 DEBUG(dbgs() << "LAA: Found a write-only loop!\n");
1052 // Build dependence sets and check whether we need a runtime pointer bounds
1054 Accesses.buildDependenceSets();
1055 bool NeedRTCheck = Accesses.isRTCheckNeeded();
1057 // Find pointers with computable bounds. We are going to use this information
1058 // to place a runtime bound check.
1059 unsigned NumComparisons = 0;
1060 bool CanDoRT = false;
1062 CanDoRT = Accesses.canCheckPtrAtRT(PtrRtCheck, NumComparisons, SE, TheLoop,
1065 DEBUG(dbgs() << "LAA: We need to do " << NumComparisons <<
1066 " pointer comparisons.\n");
1068 // If we only have one set of dependences to check pointers among we don't
1069 // need a runtime check.
1070 if (NumComparisons == 0 && NeedRTCheck)
1071 NeedRTCheck = false;
1073 // Check that we did not collect too many pointers or found an unsizeable
1076 NumComparisons > VectorizerParams::RuntimeMemoryCheckThreshold) {
1082 DEBUG(dbgs() << "LAA: We can perform a memory runtime check if needed.\n");
1085 if (NeedRTCheck && !CanDoRT) {
1086 emitAnalysis(VectorizationReport() << "cannot identify array bounds");
1087 DEBUG(dbgs() << "LAA: We can't vectorize because we can't find " <<
1088 "the array bounds.\n");
1094 PtrRtCheck.Need = NeedRTCheck;
1097 if (Accesses.isDependencyCheckNeeded()) {
1098 DEBUG(dbgs() << "LAA: Checking memory dependencies\n");
1099 CanVecMem = DepChecker.areDepsSafe(
1100 DependentAccesses, Accesses.getDependenciesToCheck(), Strides);
1101 MaxSafeDepDistBytes = DepChecker.getMaxSafeDepDistBytes();
1103 if (!CanVecMem && DepChecker.shouldRetryWithRuntimeCheck()) {
1104 DEBUG(dbgs() << "LAA: Retrying with memory checks\n");
1107 // Clear the dependency checks. We assume they are not needed.
1108 Accesses.resetDepChecks();
1111 PtrRtCheck.Need = true;
1113 CanDoRT = Accesses.canCheckPtrAtRT(PtrRtCheck, NumComparisons, SE,
1114 TheLoop, Strides, true);
1115 // Check that we did not collect too many pointers or found an unsizeable
1118 NumComparisons > VectorizerParams::RuntimeMemoryCheckThreshold) {
1119 if (!CanDoRT && NumComparisons > 0)
1120 emitAnalysis(VectorizationReport()
1121 << "cannot check memory dependencies at runtime");
1123 emitAnalysis(VectorizationReport()
1124 << NumComparisons << " exceeds limit of "
1125 << VectorizerParams::RuntimeMemoryCheckThreshold
1126 << " dependent memory operations checked at runtime");
1127 DEBUG(dbgs() << "LAA: Can't vectorize with memory checks\n");
1138 emitAnalysis(VectorizationReport() <<
1139 "unsafe dependent memory operations in loop");
1141 DEBUG(dbgs() << "LAA: We" << (NeedRTCheck ? "" : " don't") <<
1142 " need a runtime memory check.\n");
1145 bool LoopAccessInfo::blockNeedsPredication(BasicBlock *BB, Loop *TheLoop,
1146 DominatorTree *DT) {
1147 assert(TheLoop->contains(BB) && "Unknown block used");
1149 // Blocks that do not dominate the latch need predication.
1150 BasicBlock* Latch = TheLoop->getLoopLatch();
1151 return !DT->dominates(BB, Latch);
1154 void LoopAccessInfo::emitAnalysis(VectorizationReport &Message) {
1155 assert(!Report && "Multiple report generated");
1159 bool LoopAccessInfo::isUniform(Value *V) {
1160 return (SE->isLoopInvariant(SE->getSCEV(V), TheLoop));
1163 // FIXME: this function is currently a duplicate of the one in
1164 // LoopVectorize.cpp.
1165 static Instruction *getFirstInst(Instruction *FirstInst, Value *V,
1169 if (Instruction *I = dyn_cast<Instruction>(V))
1170 return I->getParent() == Loc->getParent() ? I : nullptr;
1174 std::pair<Instruction *, Instruction *>
1175 LoopAccessInfo::addRuntimeCheck(Instruction *Loc) {
1176 Instruction *tnullptr = nullptr;
1177 if (!PtrRtCheck.Need)
1178 return std::pair<Instruction *, Instruction *>(tnullptr, tnullptr);
1180 unsigned NumPointers = PtrRtCheck.Pointers.size();
1181 SmallVector<TrackingVH<Value> , 2> Starts;
1182 SmallVector<TrackingVH<Value> , 2> Ends;
1184 LLVMContext &Ctx = Loc->getContext();
1185 SCEVExpander Exp(*SE, "induction");
1186 Instruction *FirstInst = nullptr;
1188 for (unsigned i = 0; i < NumPointers; ++i) {
1189 Value *Ptr = PtrRtCheck.Pointers[i];
1190 const SCEV *Sc = SE->getSCEV(Ptr);
1192 if (SE->isLoopInvariant(Sc, TheLoop)) {
1193 DEBUG(dbgs() << "LAA: Adding RT check for a loop invariant ptr:" <<
1195 Starts.push_back(Ptr);
1196 Ends.push_back(Ptr);
1198 DEBUG(dbgs() << "LAA: Adding RT check for range:" << *Ptr << '\n');
1199 unsigned AS = Ptr->getType()->getPointerAddressSpace();
1201 // Use this type for pointer arithmetic.
1202 Type *PtrArithTy = Type::getInt8PtrTy(Ctx, AS);
1204 Value *Start = Exp.expandCodeFor(PtrRtCheck.Starts[i], PtrArithTy, Loc);
1205 Value *End = Exp.expandCodeFor(PtrRtCheck.Ends[i], PtrArithTy, Loc);
1206 Starts.push_back(Start);
1207 Ends.push_back(End);
1211 IRBuilder<> ChkBuilder(Loc);
1212 // Our instructions might fold to a constant.
1213 Value *MemoryRuntimeCheck = nullptr;
1214 for (unsigned i = 0; i < NumPointers; ++i) {
1215 for (unsigned j = i+1; j < NumPointers; ++j) {
1216 if (!PtrRtCheck.needsChecking(i, j))
1219 unsigned AS0 = Starts[i]->getType()->getPointerAddressSpace();
1220 unsigned AS1 = Starts[j]->getType()->getPointerAddressSpace();
1222 assert((AS0 == Ends[j]->getType()->getPointerAddressSpace()) &&
1223 (AS1 == Ends[i]->getType()->getPointerAddressSpace()) &&
1224 "Trying to bounds check pointers with different address spaces");
1226 Type *PtrArithTy0 = Type::getInt8PtrTy(Ctx, AS0);
1227 Type *PtrArithTy1 = Type::getInt8PtrTy(Ctx, AS1);
1229 Value *Start0 = ChkBuilder.CreateBitCast(Starts[i], PtrArithTy0, "bc");
1230 Value *Start1 = ChkBuilder.CreateBitCast(Starts[j], PtrArithTy1, "bc");
1231 Value *End0 = ChkBuilder.CreateBitCast(Ends[i], PtrArithTy1, "bc");
1232 Value *End1 = ChkBuilder.CreateBitCast(Ends[j], PtrArithTy0, "bc");
1234 Value *Cmp0 = ChkBuilder.CreateICmpULE(Start0, End1, "bound0");
1235 FirstInst = getFirstInst(FirstInst, Cmp0, Loc);
1236 Value *Cmp1 = ChkBuilder.CreateICmpULE(Start1, End0, "bound1");
1237 FirstInst = getFirstInst(FirstInst, Cmp1, Loc);
1238 Value *IsConflict = ChkBuilder.CreateAnd(Cmp0, Cmp1, "found.conflict");
1239 FirstInst = getFirstInst(FirstInst, IsConflict, Loc);
1240 if (MemoryRuntimeCheck) {
1241 IsConflict = ChkBuilder.CreateOr(MemoryRuntimeCheck, IsConflict,
1243 FirstInst = getFirstInst(FirstInst, IsConflict, Loc);
1245 MemoryRuntimeCheck = IsConflict;
1249 // We have to do this trickery because the IRBuilder might fold the check to a
1250 // constant expression in which case there is no Instruction anchored in a
1252 Instruction *Check = BinaryOperator::CreateAnd(MemoryRuntimeCheck,
1253 ConstantInt::getTrue(Ctx));
1254 ChkBuilder.Insert(Check, "memcheck.conflict");
1255 FirstInst = getFirstInst(FirstInst, Check, Loc);
1256 return std::make_pair(FirstInst, Check);
1259 LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
1260 const DataLayout *DL,
1261 const TargetLibraryInfo *TLI, AliasAnalysis *AA,
1262 DominatorTree *DT, ValueToValueMap &Strides)
1263 : TheLoop(L), SE(SE), DL(DL), TLI(TLI), AA(AA), DT(DT), NumLoads(0),
1264 NumStores(0), MaxSafeDepDistBytes(-1U), CanVecMem(false) {
1265 if (canAnalyzeLoop())
1266 analyzeLoop(Strides);
1269 LoopAccessInfo &LoopAccessAnalysis::getInfo(Loop *L, ValueToValueMap &Strides) {
1270 auto &LAI = LoopAccessInfoMap[L];
1273 assert((!LAI || LAI->NumSymbolicStrides == Strides.size()) &&
1274 "Symbolic strides changed for loop");
1278 LAI = make_unique<LoopAccessInfo>(L, SE, DL, TLI, AA, DT, Strides);
1280 LAI->NumSymbolicStrides = Strides.size();
1286 bool LoopAccessAnalysis::runOnFunction(Function &F) {
1287 SE = &getAnalysis<ScalarEvolution>();
1288 DL = F.getParent()->getDataLayout();
1289 auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
1290 TLI = TLIP ? &TLIP->getTLI() : nullptr;
1291 AA = &getAnalysis<AliasAnalysis>();
1292 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1297 void LoopAccessAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
1298 AU.addRequired<ScalarEvolution>();
1299 AU.addRequired<AliasAnalysis>();
1300 AU.addRequired<DominatorTreeWrapperPass>();
1302 AU.setPreservesAll();
1305 char LoopAccessAnalysis::ID = 0;
1306 static const char laa_name[] = "Loop Access Analysis";
1307 #define LAA_NAME "loop-accesses"
1309 INITIALIZE_PASS_BEGIN(LoopAccessAnalysis, LAA_NAME, laa_name, false, true)
1310 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
1311 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
1312 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
1313 INITIALIZE_PASS_END(LoopAccessAnalysis, LAA_NAME, laa_name, false, true)
1316 Pass *createLAAPass() {
1317 return new LoopAccessAnalysis();