diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/lib/Analysis/BasicAliasAnalysis.cpp | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | contrib/libs/llvm12/lib/Analysis/BasicAliasAnalysis.cpp | 652 |
1 files changed, 326 insertions, 326 deletions
diff --git a/contrib/libs/llvm12/lib/Analysis/BasicAliasAnalysis.cpp b/contrib/libs/llvm12/lib/Analysis/BasicAliasAnalysis.cpp index 97d0cb63ef..18b0263ff6 100644 --- a/contrib/libs/llvm12/lib/Analysis/BasicAliasAnalysis.cpp +++ b/contrib/libs/llvm12/lib/Analysis/BasicAliasAnalysis.cpp @@ -14,7 +14,7 @@ #include "llvm/Analysis/BasicAliasAnalysis.h" #include "llvm/ADT/APInt.h" -#include "llvm/ADT/ScopeExit.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" @@ -67,7 +67,7 @@ using namespace llvm; /// Enable analysis of recursive PHI nodes. static cl::opt<bool> EnableRecPhiAnalysis("basic-aa-recphi", cl::Hidden, - cl::init(true)); + cl::init(true)); /// By default, even on 32-bit architectures we use 64-bit integers for /// calculations. This will allow us to more-aggressively decompose indexing @@ -92,7 +92,7 @@ STATISTIC(SearchTimes, "Number of times a GEP is decomposed"); const unsigned MaxNumPhiBBsValueReachabilityCheck = 20; // The max limit of the search depth in DecomposeGEPExpression() and -// getUnderlyingObject(), both functions need to use the same search +// getUnderlyingObject(), both functions need to use the same search // depth otherwise the algorithm in aliasGEP will assert. static const unsigned MaxLookupSearchDepth = 6; @@ -412,22 +412,22 @@ static unsigned getMaxPointerSize(const DataLayout &DL) { /// specified amount, but which may have other unrepresented high bits. As /// such, the gep cannot necessarily be reconstructed from its decomposed form. /// -/// This function is capable of analyzing everything that getUnderlyingObject -/// can look through. To be able to do that getUnderlyingObject and -/// DecomposeGEPExpression must use the same search depth -/// (MaxLookupSearchDepth). -BasicAAResult::DecomposedGEP -BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, - AssumptionCache *AC, DominatorTree *DT) { +/// This function is capable of analyzing everything that getUnderlyingObject +/// can look through. To be able to do that getUnderlyingObject and +/// DecomposeGEPExpression must use the same search depth +/// (MaxLookupSearchDepth). +BasicAAResult::DecomposedGEP +BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, + AssumptionCache *AC, DominatorTree *DT) { // Limit recursion depth to limit compile time in crazy cases. unsigned MaxLookup = MaxLookupSearchDepth; SearchTimes++; - const Instruction *CxtI = dyn_cast<Instruction>(V); + const Instruction *CxtI = dyn_cast<Instruction>(V); unsigned MaxPointerSize = getMaxPointerSize(DL); - DecomposedGEP Decomposed; - Decomposed.Offset = APInt(MaxPointerSize, 0); - Decomposed.HasCompileTimeConstantScale = true; + DecomposedGEP Decomposed; + Decomposed.Offset = APInt(MaxPointerSize, 0); + Decomposed.HasCompileTimeConstantScale = true; do { // See if this is a bitcast or GEP. const Operator *Op = dyn_cast<Operator>(V); @@ -440,7 +440,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, } } Decomposed.Base = V; - return Decomposed; + return Decomposed; } if (Op->getOpcode() == Instruction::BitCast || @@ -474,13 +474,13 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, } Decomposed.Base = V; - return Decomposed; + return Decomposed; } // Don't attempt to analyze GEPs over unsized objects. if (!GEPOp->getSourceElementType()->isSized()) { Decomposed.Base = V; - return Decomposed; + return Decomposed; } // Don't attempt to analyze GEPs if index scale is not a compile-time @@ -488,7 +488,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, if (isa<ScalableVectorType>(GEPOp->getSourceElementType())) { Decomposed.Base = V; Decomposed.HasCompileTimeConstantScale = false; - return Decomposed; + return Decomposed; } unsigned AS = GEPOp->getPointerAddressSpace(); @@ -507,7 +507,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, if (FieldNo == 0) continue; - Decomposed.Offset += DL.getStructLayout(STy)->getElementOffset(FieldNo); + Decomposed.Offset += DL.getStructLayout(STy)->getElementOffset(FieldNo); continue; } @@ -515,9 +515,9 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, if (const ConstantInt *CIdx = dyn_cast<ConstantInt>(Index)) { if (CIdx->isZero()) continue; - Decomposed.Offset += - DL.getTypeAllocSize(GTI.getIndexedType()).getFixedSize() * - CIdx->getValue().sextOrTrunc(MaxPointerSize); + Decomposed.Offset += + DL.getTypeAllocSize(GTI.getIndexedType()).getFixedSize() * + CIdx->getValue().sextOrTrunc(MaxPointerSize); continue; } @@ -550,10 +550,10 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, // FIXME: C1*Scale and the other operations in the decomposed // (C1*Scale)*V+C2*Scale can also overflow. We should check for this // possibility. - bool Overflow; - APInt ScaledOffset = IndexOffset.sextOrTrunc(MaxPointerSize) - .smul_ov(Scale, Overflow); - if (Overflow) { + bool Overflow; + APInt ScaledOffset = IndexOffset.sextOrTrunc(MaxPointerSize) + .smul_ov(Scale, Overflow); + if (Overflow) { Index = OrigIndex; IndexScale = 1; IndexOffset = 0; @@ -562,7 +562,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, if (PointerSize > Width) SExtBits += PointerSize - Width; } else { - Decomposed.Offset += ScaledOffset; + Decomposed.Offset += ScaledOffset; Scale *= IndexScale.sextOrTrunc(MaxPointerSize); } @@ -585,14 +585,14 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, Scale = adjustToPointerSize(Scale, PointerSize); if (!!Scale) { - VariableGEPIndex Entry = {Index, ZExtBits, SExtBits, Scale, CxtI}; + VariableGEPIndex Entry = {Index, ZExtBits, SExtBits, Scale, CxtI}; Decomposed.VarIndices.push_back(Entry); } } // Take care of wrap-arounds - if (GepHasConstantOffset) - Decomposed.Offset = adjustToPointerSize(Decomposed.Offset, PointerSize); + if (GepHasConstantOffset) + Decomposed.Offset = adjustToPointerSize(Decomposed.Offset, PointerSize); // Analyze the base pointer next. V = GEPOp->getOperand(0); @@ -601,7 +601,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, // If the chain of expressions is too deep, just return early. Decomposed.Base = V; SearchLimitReached++; - return Decomposed; + return Decomposed; } /// Returns whether the given pointer value points to memory that is local to @@ -615,7 +615,7 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc, SmallVector<const Value *, 16> Worklist; Worklist.push_back(Loc.Ptr); do { - const Value *V = getUnderlyingObject(Worklist.pop_back_val()); + const Value *V = getUnderlyingObject(Worklist.pop_back_val()); if (!Visited.insert(V).second) { Visited.clear(); return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal); @@ -652,7 +652,7 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc, Visited.clear(); return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal); } - append_range(Worklist, PN->incoming_values()); + append_range(Worklist, PN->incoming_values()); continue; } @@ -797,8 +797,8 @@ AliasResult BasicAAResult::alias(const MemoryLocation &LocA, AAQueryInfo &AAQI) { assert(notDifferentParent(LocA.Ptr, LocB.Ptr) && "BasicAliasAnalysis doesn't support interprocedural queries."); - return aliasCheck(LocA.Ptr, LocA.Size, LocA.AATags, LocB.Ptr, LocB.Size, - LocB.AATags, AAQI); + return aliasCheck(LocA.Ptr, LocA.Size, LocA.AATags, LocB.Ptr, LocB.Size, + LocB.AATags, AAQI); } /// Checks to see if the specified callsite can clobber the specified memory @@ -813,7 +813,7 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call, assert(notDifferentParent(Call, Loc.Ptr) && "AliasAnalysis query involving multiple functions!"); - const Value *Object = getUnderlyingObject(Loc.Ptr); + const Value *Object = getUnderlyingObject(Loc.Ptr); // Calls marked 'tail' cannot read or write allocas from the current frame // because the current frame might be destroyed by the time they run. However, @@ -862,9 +862,9 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call, // If this is a no-capture pointer argument, see if we can tell that it // is impossible to alias the pointer we're checking. - AliasResult AR = getBestAAResults().alias( - MemoryLocation::getBeforeOrAfter(*CI), - MemoryLocation::getBeforeOrAfter(Object), AAQI); + AliasResult AR = getBestAAResults().alias( + MemoryLocation::getBeforeOrAfter(*CI), + MemoryLocation::getBeforeOrAfter(Object), AAQI); if (AR != MustAlias) IsMustAlias = false; // Operand doesn't alias 'Object', continue looking for other aliases @@ -910,19 +910,19 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call, if (isMallocOrCallocLikeFn(Call, &TLI)) { // Be conservative if the accessed pointer may alias the allocation - // fallback to the generic handling below. - if (getBestAAResults().alias(MemoryLocation::getBeforeOrAfter(Call), - Loc, AAQI) == NoAlias) + if (getBestAAResults().alias(MemoryLocation::getBeforeOrAfter(Call), + Loc, AAQI) == NoAlias) return ModRefInfo::NoModRef; } - // The semantics of memcpy intrinsics either exactly overlap or do not - // overlap, i.e., source and destination of any given memcpy are either - // no-alias or must-alias. + // The semantics of memcpy intrinsics either exactly overlap or do not + // overlap, i.e., source and destination of any given memcpy are either + // no-alias or must-alias. if (auto *Inst = dyn_cast<AnyMemCpyInst>(Call)) { - AliasResult SrcAA = - getBestAAResults().alias(MemoryLocation::getForSource(Inst), Loc, AAQI); - AliasResult DestAA = - getBestAAResults().alias(MemoryLocation::getForDest(Inst), Loc, AAQI); + AliasResult SrcAA = + getBestAAResults().alias(MemoryLocation::getForSource(Inst), Loc, AAQI); + AliasResult DestAA = + getBestAAResults().alias(MemoryLocation::getForDest(Inst), Loc, AAQI); // It's also possible for Loc to alias both src and dest, or neither. ModRefInfo rv = ModRefInfo::NoModRef; if (SrcAA != NoAlias) @@ -947,9 +947,9 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call, // the guard invokes the "deopt" continuation. if (isIntrinsicCall(Call, Intrinsic::experimental_guard)) return ModRefInfo::Ref; - // The same applies to deoptimize which is essentially a guard(false). - if (isIntrinsicCall(Call, Intrinsic::experimental_deoptimize)) - return ModRefInfo::Ref; + // The same applies to deoptimize which is essentially a guard(false). + if (isIntrinsicCall(Call, Intrinsic::experimental_deoptimize)) + return ModRefInfo::Ref; // Like assumes, invariant.start intrinsics were also marked as arbitrarily // writing so that proper control dependencies are maintained but they never @@ -1051,7 +1051,7 @@ bool BasicAAResult::isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp, const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompObject, LocationSize MaybeObjectAccessSize) { // If the object access size is unknown, or the GEP isn't inbounds, bail. - if (!MaybeObjectAccessSize.hasValue() || !GEPOp->isInBounds()) + if (!MaybeObjectAccessSize.hasValue() || !GEPOp->isInBounds()) return false; const uint64_t ObjectAccessSize = MaybeObjectAccessSize.getValue(); @@ -1071,21 +1071,21 @@ bool BasicAAResult::isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp, if (!DecompGEP.VarIndices.empty()) return false; - return DecompGEP.Offset.sge(DecompObject.Offset + (int64_t)ObjectAccessSize); + return DecompGEP.Offset.sge(DecompObject.Offset + (int64_t)ObjectAccessSize); } /// Provides a bunch of ad-hoc rules to disambiguate a GEP instruction against /// another pointer. /// /// We know that V1 is a GEP, but we don't know anything about V2. -/// UnderlyingV1 is getUnderlyingObject(GEP1), UnderlyingV2 is the same for +/// UnderlyingV1 is getUnderlyingObject(GEP1), UnderlyingV2 is the same for /// V2. AliasResult BasicAAResult::aliasGEP( const GEPOperator *GEP1, LocationSize V1Size, const AAMDNodes &V1AAInfo, const Value *V2, LocationSize V2Size, const AAMDNodes &V2AAInfo, const Value *UnderlyingV1, const Value *UnderlyingV2, AAQueryInfo &AAQI) { - DecomposedGEP DecompGEP1 = DecomposeGEPExpression(GEP1, DL, &AC, DT); - DecomposedGEP DecompGEP2 = DecomposeGEPExpression(V2, DL, &AC, DT); + DecomposedGEP DecompGEP1 = DecomposeGEPExpression(GEP1, DL, &AC, DT); + DecomposedGEP DecompGEP2 = DecomposeGEPExpression(V2, DL, &AC, DT); // Don't attempt to analyze the decomposed GEP if index scale is not a // compile-time constant. @@ -1095,12 +1095,12 @@ AliasResult BasicAAResult::aliasGEP( assert(DecompGEP1.Base == UnderlyingV1 && DecompGEP2.Base == UnderlyingV2 && "DecomposeGEPExpression returned a result different from " - "getUnderlyingObject"); + "getUnderlyingObject"); // If the GEP's offset relative to its base is such that the base would // fall below the start of the object underlying V2, then the GEP and V2 // cannot alias. - if (isGEPBaseAtNegativeOffset(GEP1, DecompGEP1, DecompGEP2, V2Size)) + if (isGEPBaseAtNegativeOffset(GEP1, DecompGEP1, DecompGEP2, V2Size)) return NoAlias; // If we have two gep instructions with must-alias or not-alias'ing base // pointers, figure out if the indexes to the GEP tell us anything about the @@ -1108,22 +1108,22 @@ AliasResult BasicAAResult::aliasGEP( if (const GEPOperator *GEP2 = dyn_cast<GEPOperator>(V2)) { // Check for the GEP base being at a negative offset, this time in the other // direction. - if (isGEPBaseAtNegativeOffset(GEP2, DecompGEP2, DecompGEP1, V1Size)) + if (isGEPBaseAtNegativeOffset(GEP2, DecompGEP2, DecompGEP1, V1Size)) return NoAlias; // Do the base pointers alias? - AliasResult BaseAlias = getBestAAResults().alias( - MemoryLocation::getBeforeOrAfter(UnderlyingV1), - MemoryLocation::getBeforeOrAfter(UnderlyingV2), AAQI); - - // For GEPs with identical offsets, we can preserve the size and AAInfo - // when performing the alias check on the underlying objects. - if (BaseAlias == MayAlias && DecompGEP1.Offset == DecompGEP2.Offset && - DecompGEP1.VarIndices == DecompGEP2.VarIndices) { - AliasResult PreciseBaseAlias = getBestAAResults().alias( - MemoryLocation(UnderlyingV1, V1Size, V1AAInfo), - MemoryLocation(UnderlyingV2, V2Size, V2AAInfo), AAQI); - if (PreciseBaseAlias == NoAlias) - return NoAlias; + AliasResult BaseAlias = getBestAAResults().alias( + MemoryLocation::getBeforeOrAfter(UnderlyingV1), + MemoryLocation::getBeforeOrAfter(UnderlyingV2), AAQI); + + // For GEPs with identical offsets, we can preserve the size and AAInfo + // when performing the alias check on the underlying objects. + if (BaseAlias == MayAlias && DecompGEP1.Offset == DecompGEP2.Offset && + DecompGEP1.VarIndices == DecompGEP2.VarIndices) { + AliasResult PreciseBaseAlias = getBestAAResults().alias( + MemoryLocation(UnderlyingV1, V1Size, V1AAInfo), + MemoryLocation(UnderlyingV2, V2Size, V2AAInfo), AAQI); + if (PreciseBaseAlias == NoAlias) + return NoAlias; } // If we get a No or May, then return it immediately, no amount of analysis @@ -1135,7 +1135,7 @@ AliasResult BasicAAResult::aliasGEP( // Subtract the GEP2 pointer from the GEP1 pointer to find out their // symbolic difference. - DecompGEP1.Offset -= DecompGEP2.Offset; + DecompGEP1.Offset -= DecompGEP2.Offset; GetIndexDifference(DecompGEP1.VarIndices, DecompGEP2.VarIndices); } else { @@ -1144,12 +1144,12 @@ AliasResult BasicAAResult::aliasGEP( // pointer, we know they cannot alias. // If both accesses are unknown size, we can't do anything useful here. - if (!V1Size.hasValue() && !V2Size.hasValue()) + if (!V1Size.hasValue() && !V2Size.hasValue()) return MayAlias; - AliasResult R = getBestAAResults().alias( - MemoryLocation::getBeforeOrAfter(UnderlyingV1), - MemoryLocation(V2, V2Size, V2AAInfo), AAQI); + AliasResult R = getBestAAResults().alias( + MemoryLocation::getBeforeOrAfter(UnderlyingV1), + MemoryLocation(V2, V2Size, V2AAInfo), AAQI); if (R != MustAlias) { // If V2 may alias GEP base pointer, conservatively returns MayAlias. // If V2 is known not to alias GEP base pointer, then the two values @@ -1167,17 +1167,17 @@ AliasResult BasicAAResult::aliasGEP( // // In the other case, if we have getelementptr <ptr>, 0, 0, 0, 0, ... and V2 // must aliases the GEP, the end result is a must alias also. - if (DecompGEP1.Offset == 0 && DecompGEP1.VarIndices.empty()) + if (DecompGEP1.Offset == 0 && DecompGEP1.VarIndices.empty()) return MustAlias; // If there is a constant difference between the pointers, but the difference // is less than the size of the associated memory object, then we know // that the objects are partially overlapping. If the difference is // greater, we know they do not overlap. - if (DecompGEP1.Offset != 0 && DecompGEP1.VarIndices.empty()) { - if (DecompGEP1.Offset.sge(0)) { - if (V2Size.hasValue()) { - if (DecompGEP1.Offset.ult(V2Size.getValue())) + if (DecompGEP1.Offset != 0 && DecompGEP1.VarIndices.empty()) { + if (DecompGEP1.Offset.sge(0)) { + if (V2Size.hasValue()) { + if (DecompGEP1.Offset.ult(V2Size.getValue())) return PartialAlias; return NoAlias; } @@ -1188,8 +1188,8 @@ AliasResult BasicAAResult::aliasGEP( // ---------------->| // |-->V1Size |-------> V2Size // GEP1 V2 - if (V1Size.hasValue()) { - if ((-DecompGEP1.Offset).ult(V1Size.getValue())) + if (V1Size.hasValue()) { + if ((-DecompGEP1.Offset).ult(V1Size.getValue())) return PartialAlias; return NoAlias; } @@ -1197,24 +1197,24 @@ AliasResult BasicAAResult::aliasGEP( } if (!DecompGEP1.VarIndices.empty()) { - APInt GCD; - bool AllNonNegative = DecompGEP1.Offset.isNonNegative(); - bool AllNonPositive = DecompGEP1.Offset.isNonPositive(); + APInt GCD; + bool AllNonNegative = DecompGEP1.Offset.isNonNegative(); + bool AllNonPositive = DecompGEP1.Offset.isNonPositive(); for (unsigned i = 0, e = DecompGEP1.VarIndices.size(); i != e; ++i) { - const APInt &Scale = DecompGEP1.VarIndices[i].Scale; - if (i == 0) - GCD = Scale.abs(); - else - GCD = APIntOps::GreatestCommonDivisor(GCD, Scale.abs()); + const APInt &Scale = DecompGEP1.VarIndices[i].Scale; + if (i == 0) + GCD = Scale.abs(); + else + GCD = APIntOps::GreatestCommonDivisor(GCD, Scale.abs()); - if (AllNonNegative || AllNonPositive) { + if (AllNonNegative || AllNonPositive) { // If the Value could change between cycles, then any reasoning about // the Value this cycle may not hold in the next cycle. We'll just // give up if we can't determine conditions that hold for every cycle: const Value *V = DecompGEP1.VarIndices[i].V; - const Instruction *CxtI = DecompGEP1.VarIndices[i].CxtI; + const Instruction *CxtI = DecompGEP1.VarIndices[i].CxtI; - KnownBits Known = computeKnownBits(V, DL, 0, &AC, CxtI, DT); + KnownBits Known = computeKnownBits(V, DL, 0, &AC, CxtI, DT); bool SignKnownZero = Known.isNonNegative(); bool SignKnownOne = Known.isNegative(); @@ -1224,77 +1224,77 @@ AliasResult BasicAAResult::aliasGEP( SignKnownZero |= IsZExt; SignKnownOne &= !IsZExt; - AllNonNegative &= (SignKnownZero && Scale.isNonNegative()) || - (SignKnownOne && Scale.isNonPositive()); - AllNonPositive &= (SignKnownZero && Scale.isNonPositive()) || - (SignKnownOne && Scale.isNonNegative()); + AllNonNegative &= (SignKnownZero && Scale.isNonNegative()) || + (SignKnownOne && Scale.isNonPositive()); + AllNonPositive &= (SignKnownZero && Scale.isNonPositive()) || + (SignKnownOne && Scale.isNonNegative()); } } - // We now have accesses at two offsets from the same base: - // 1. (...)*GCD + DecompGEP1.Offset with size V1Size - // 2. 0 with size V2Size - // Using arithmetic modulo GCD, the accesses are at - // [ModOffset..ModOffset+V1Size) and [0..V2Size). If the first access fits - // into the range [V2Size..GCD), then we know they cannot overlap. - APInt ModOffset = DecompGEP1.Offset.srem(GCD); - if (ModOffset.isNegative()) - ModOffset += GCD; // We want mod, not rem. - if (V1Size.hasValue() && V2Size.hasValue() && - ModOffset.uge(V2Size.getValue()) && - (GCD - ModOffset).uge(V1Size.getValue())) + // We now have accesses at two offsets from the same base: + // 1. (...)*GCD + DecompGEP1.Offset with size V1Size + // 2. 0 with size V2Size + // Using arithmetic modulo GCD, the accesses are at + // [ModOffset..ModOffset+V1Size) and [0..V2Size). If the first access fits + // into the range [V2Size..GCD), then we know they cannot overlap. + APInt ModOffset = DecompGEP1.Offset.srem(GCD); + if (ModOffset.isNegative()) + ModOffset += GCD; // We want mod, not rem. + if (V1Size.hasValue() && V2Size.hasValue() && + ModOffset.uge(V2Size.getValue()) && + (GCD - ModOffset).uge(V1Size.getValue())) return NoAlias; - // If we know all the variables are non-negative, then the total offset is - // also non-negative and >= DecompGEP1.Offset. We have the following layout: - // [0, V2Size) ... [TotalOffset, TotalOffer+V1Size] - // If DecompGEP1.Offset >= V2Size, the accesses don't alias. - if (AllNonNegative && V2Size.hasValue() && - DecompGEP1.Offset.uge(V2Size.getValue())) - return NoAlias; - // Similarly, if the variables are non-positive, then the total offset is - // also non-positive and <= DecompGEP1.Offset. We have the following layout: - // [TotalOffset, TotalOffset+V1Size) ... [0, V2Size) - // If -DecompGEP1.Offset >= V1Size, the accesses don't alias. - if (AllNonPositive && V1Size.hasValue() && - (-DecompGEP1.Offset).uge(V1Size.getValue())) + // If we know all the variables are non-negative, then the total offset is + // also non-negative and >= DecompGEP1.Offset. We have the following layout: + // [0, V2Size) ... [TotalOffset, TotalOffer+V1Size] + // If DecompGEP1.Offset >= V2Size, the accesses don't alias. + if (AllNonNegative && V2Size.hasValue() && + DecompGEP1.Offset.uge(V2Size.getValue())) return NoAlias; - - if (V1Size.hasValue() && V2Size.hasValue()) { - // Try to determine whether abs(VarIndex) > 0. - Optional<APInt> MinAbsVarIndex; - if (DecompGEP1.VarIndices.size() == 1) { - // VarIndex = Scale*V. If V != 0 then abs(VarIndex) >= abs(Scale). - const VariableGEPIndex &Var = DecompGEP1.VarIndices[0]; - if (isKnownNonZero(Var.V, DL, 0, &AC, Var.CxtI, DT)) - MinAbsVarIndex = Var.Scale.abs(); - } else if (DecompGEP1.VarIndices.size() == 2) { - // VarIndex = Scale*V0 + (-Scale)*V1. - // If V0 != V1 then abs(VarIndex) >= abs(Scale). - // Check that VisitedPhiBBs is empty, to avoid reasoning about - // inequality of values across loop iterations. - const VariableGEPIndex &Var0 = DecompGEP1.VarIndices[0]; - const VariableGEPIndex &Var1 = DecompGEP1.VarIndices[1]; - if (Var0.Scale == -Var1.Scale && Var0.ZExtBits == Var1.ZExtBits && - Var0.SExtBits == Var1.SExtBits && VisitedPhiBBs.empty() && - isKnownNonEqual(Var0.V, Var1.V, DL, &AC, /* CxtI */ nullptr, DT)) - MinAbsVarIndex = Var0.Scale.abs(); - } - - if (MinAbsVarIndex) { - // The constant offset will have added at least +/-MinAbsVarIndex to it. - APInt OffsetLo = DecompGEP1.Offset - *MinAbsVarIndex; - APInt OffsetHi = DecompGEP1.Offset + *MinAbsVarIndex; - // Check that an access at OffsetLo or lower, and an access at OffsetHi - // or higher both do not alias. - if (OffsetLo.isNegative() && (-OffsetLo).uge(V1Size.getValue()) && - OffsetHi.isNonNegative() && OffsetHi.uge(V2Size.getValue())) - return NoAlias; - } - } - + // Similarly, if the variables are non-positive, then the total offset is + // also non-positive and <= DecompGEP1.Offset. We have the following layout: + // [TotalOffset, TotalOffset+V1Size) ... [0, V2Size) + // If -DecompGEP1.Offset >= V1Size, the accesses don't alias. + if (AllNonPositive && V1Size.hasValue() && + (-DecompGEP1.Offset).uge(V1Size.getValue())) + return NoAlias; + + if (V1Size.hasValue() && V2Size.hasValue()) { + // Try to determine whether abs(VarIndex) > 0. + Optional<APInt> MinAbsVarIndex; + if (DecompGEP1.VarIndices.size() == 1) { + // VarIndex = Scale*V. If V != 0 then abs(VarIndex) >= abs(Scale). + const VariableGEPIndex &Var = DecompGEP1.VarIndices[0]; + if (isKnownNonZero(Var.V, DL, 0, &AC, Var.CxtI, DT)) + MinAbsVarIndex = Var.Scale.abs(); + } else if (DecompGEP1.VarIndices.size() == 2) { + // VarIndex = Scale*V0 + (-Scale)*V1. + // If V0 != V1 then abs(VarIndex) >= abs(Scale). + // Check that VisitedPhiBBs is empty, to avoid reasoning about + // inequality of values across loop iterations. + const VariableGEPIndex &Var0 = DecompGEP1.VarIndices[0]; + const VariableGEPIndex &Var1 = DecompGEP1.VarIndices[1]; + if (Var0.Scale == -Var1.Scale && Var0.ZExtBits == Var1.ZExtBits && + Var0.SExtBits == Var1.SExtBits && VisitedPhiBBs.empty() && + isKnownNonEqual(Var0.V, Var1.V, DL, &AC, /* CxtI */ nullptr, DT)) + MinAbsVarIndex = Var0.Scale.abs(); + } + + if (MinAbsVarIndex) { + // The constant offset will have added at least +/-MinAbsVarIndex to it. + APInt OffsetLo = DecompGEP1.Offset - *MinAbsVarIndex; + APInt OffsetHi = DecompGEP1.Offset + *MinAbsVarIndex; + // Check that an access at OffsetLo or lower, and an access at OffsetHi + // or higher both do not alias. + if (OffsetLo.isNegative() && (-OffsetLo).uge(V1Size.getValue()) && + OffsetHi.isNonNegative() && OffsetHi.uge(V2Size.getValue())) + return NoAlias; + } + } + if (constantOffsetHeuristic(DecompGEP1.VarIndices, V1Size, V2Size, - DecompGEP1.Offset, &AC, DT)) + DecompGEP1.Offset, &AC, DT)) return NoAlias; } @@ -1322,33 +1322,33 @@ AliasResult BasicAAResult::aliasSelect(const SelectInst *SI, LocationSize SISize, const AAMDNodes &SIAAInfo, const Value *V2, LocationSize V2Size, const AAMDNodes &V2AAInfo, - AAQueryInfo &AAQI) { + AAQueryInfo &AAQI) { // If the values are Selects with the same condition, we can do a more precise // check: just check for aliases between the values on corresponding arms. if (const SelectInst *SI2 = dyn_cast<SelectInst>(V2)) if (SI->getCondition() == SI2->getCondition()) { - AliasResult Alias = getBestAAResults().alias( - MemoryLocation(SI->getTrueValue(), SISize, SIAAInfo), - MemoryLocation(SI2->getTrueValue(), V2Size, V2AAInfo), AAQI); + AliasResult Alias = getBestAAResults().alias( + MemoryLocation(SI->getTrueValue(), SISize, SIAAInfo), + MemoryLocation(SI2->getTrueValue(), V2Size, V2AAInfo), AAQI); if (Alias == MayAlias) return MayAlias; - AliasResult ThisAlias = getBestAAResults().alias( - MemoryLocation(SI->getFalseValue(), SISize, SIAAInfo), - MemoryLocation(SI2->getFalseValue(), V2Size, V2AAInfo), AAQI); + AliasResult ThisAlias = getBestAAResults().alias( + MemoryLocation(SI->getFalseValue(), SISize, SIAAInfo), + MemoryLocation(SI2->getFalseValue(), V2Size, V2AAInfo), AAQI); return MergeAliasResults(ThisAlias, Alias); } // If both arms of the Select node NoAlias or MustAlias V2, then returns // NoAlias / MustAlias. Otherwise, returns MayAlias. - AliasResult Alias = getBestAAResults().alias( - MemoryLocation(V2, V2Size, V2AAInfo), - MemoryLocation(SI->getTrueValue(), SISize, SIAAInfo), AAQI); + AliasResult Alias = getBestAAResults().alias( + MemoryLocation(V2, V2Size, V2AAInfo), + MemoryLocation(SI->getTrueValue(), SISize, SIAAInfo), AAQI); if (Alias == MayAlias) return MayAlias; - AliasResult ThisAlias = getBestAAResults().alias( - MemoryLocation(V2, V2Size, V2AAInfo), - MemoryLocation(SI->getFalseValue(), SISize, SIAAInfo), AAQI); + AliasResult ThisAlias = getBestAAResults().alias( + MemoryLocation(V2, V2Size, V2AAInfo), + MemoryLocation(SI->getFalseValue(), SISize, SIAAInfo), AAQI); return MergeAliasResults(ThisAlias, Alias); } @@ -1358,41 +1358,41 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize, const AAMDNodes &PNAAInfo, const Value *V2, LocationSize V2Size, const AAMDNodes &V2AAInfo, - AAQueryInfo &AAQI) { + AAQueryInfo &AAQI) { // If the values are PHIs in the same block, we can do a more precise // as well as efficient check: just check for aliases between the values // on corresponding edges. if (const PHINode *PN2 = dyn_cast<PHINode>(V2)) if (PN2->getParent() == PN->getParent()) { - Optional<AliasResult> Alias; + Optional<AliasResult> Alias; for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { - AliasResult ThisAlias = getBestAAResults().alias( - MemoryLocation(PN->getIncomingValue(i), PNSize, PNAAInfo), - MemoryLocation( - PN2->getIncomingValueForBlock(PN->getIncomingBlock(i)), V2Size, - V2AAInfo), - AAQI); - if (Alias) - *Alias = MergeAliasResults(*Alias, ThisAlias); - else - Alias = ThisAlias; - if (*Alias == MayAlias) + AliasResult ThisAlias = getBestAAResults().alias( + MemoryLocation(PN->getIncomingValue(i), PNSize, PNAAInfo), + MemoryLocation( + PN2->getIncomingValueForBlock(PN->getIncomingBlock(i)), V2Size, + V2AAInfo), + AAQI); + if (Alias) + *Alias = MergeAliasResults(*Alias, ThisAlias); + else + Alias = ThisAlias; + if (*Alias == MayAlias) break; } - return *Alias; + return *Alias; } SmallVector<Value *, 4> V1Srcs; - // If a phi operand recurses back to the phi, we can still determine NoAlias - // if we don't alias the underlying objects of the other phi operands, as we - // know that the recursive phi needs to be based on them in some way. + // If a phi operand recurses back to the phi, we can still determine NoAlias + // if we don't alias the underlying objects of the other phi operands, as we + // know that the recursive phi needs to be based on them in some way. bool isRecursive = false; auto CheckForRecPhi = [&](Value *PV) { if (!EnableRecPhiAnalysis) return false; - if (getUnderlyingObject(PV) == PN) { - isRecursive = true; - return true; + if (getUnderlyingObject(PV) == PN) { + isRecursive = true; + return true; } return false; }; @@ -1438,31 +1438,31 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize, if (V1Srcs.empty()) return MayAlias; - // If this PHI node is recursive, indicate that the pointer may be moved - // across iterations. We can only prove NoAlias if different underlying - // objects are involved. + // If this PHI node is recursive, indicate that the pointer may be moved + // across iterations. We can only prove NoAlias if different underlying + // objects are involved. if (isRecursive) - PNSize = LocationSize::beforeOrAfterPointer(); - - // In the recursive alias queries below, we may compare values from two - // different loop iterations. Keep track of visited phi blocks, which will - // be used when determining value equivalence. - bool BlockInserted = VisitedPhiBBs.insert(PN->getParent()).second; - auto _ = make_scope_exit([&]() { - if (BlockInserted) - VisitedPhiBBs.erase(PN->getParent()); - }); - - // If we inserted a block into VisitedPhiBBs, alias analysis results that - // have been cached earlier may no longer be valid. Perform recursive queries - // with a new AAQueryInfo. - AAQueryInfo NewAAQI; - AAQueryInfo *UseAAQI = BlockInserted ? &NewAAQI : &AAQI; - - AliasResult Alias = getBestAAResults().alias( - MemoryLocation(V2, V2Size, V2AAInfo), - MemoryLocation(V1Srcs[0], PNSize, PNAAInfo), *UseAAQI); - + PNSize = LocationSize::beforeOrAfterPointer(); + + // In the recursive alias queries below, we may compare values from two + // different loop iterations. Keep track of visited phi blocks, which will + // be used when determining value equivalence. + bool BlockInserted = VisitedPhiBBs.insert(PN->getParent()).second; + auto _ = make_scope_exit([&]() { + if (BlockInserted) + VisitedPhiBBs.erase(PN->getParent()); + }); + + // If we inserted a block into VisitedPhiBBs, alias analysis results that + // have been cached earlier may no longer be valid. Perform recursive queries + // with a new AAQueryInfo. + AAQueryInfo NewAAQI; + AAQueryInfo *UseAAQI = BlockInserted ? &NewAAQI : &AAQI; + + AliasResult Alias = getBestAAResults().alias( + MemoryLocation(V2, V2Size, V2AAInfo), + MemoryLocation(V1Srcs[0], PNSize, PNAAInfo), *UseAAQI); + // Early exit if the check of the first PHI source against V2 is MayAlias. // Other results are not possible. if (Alias == MayAlias) @@ -1477,9 +1477,9 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize, for (unsigned i = 1, e = V1Srcs.size(); i != e; ++i) { Value *V = V1Srcs[i]; - AliasResult ThisAlias = getBestAAResults().alias( - MemoryLocation(V2, V2Size, V2AAInfo), - MemoryLocation(V, PNSize, PNAAInfo), *UseAAQI); + AliasResult ThisAlias = getBestAAResults().alias( + MemoryLocation(V2, V2Size, V2AAInfo), + MemoryLocation(V, PNSize, PNAAInfo), *UseAAQI); Alias = MergeAliasResults(ThisAlias, Alias); if (Alias == MayAlias) break; @@ -1491,10 +1491,10 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize, /// Provides a bunch of ad-hoc rules to disambiguate in common cases, such as /// array references. AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size, - const AAMDNodes &V1AAInfo, - const Value *V2, LocationSize V2Size, - const AAMDNodes &V2AAInfo, - AAQueryInfo &AAQI) { + const AAMDNodes &V1AAInfo, + const Value *V2, LocationSize V2Size, + const AAMDNodes &V2AAInfo, + AAQueryInfo &AAQI) { // If either of the memory references is empty, it doesn't matter what the // pointer values are. if (V1Size.isZero() || V2Size.isZero()) @@ -1522,8 +1522,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size, return NoAlias; // Scalars cannot alias each other // Figure out what objects these things are pointing to if we can. - const Value *O1 = getUnderlyingObject(V1, MaxLookupSearchDepth); - const Value *O2 = getUnderlyingObject(V2, MaxLookupSearchDepth); + const Value *O1 = getUnderlyingObject(V1, MaxLookupSearchDepth); + const Value *O2 = getUnderlyingObject(V2, MaxLookupSearchDepth); // Null values in the default address space don't point to any object, so they // don't alias any other pointer. @@ -1578,120 +1578,120 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size, TLI, NullIsValidLocation))) return NoAlias; - // If one the accesses may be before the accessed pointer, canonicalize this - // by using unknown after-pointer sizes for both accesses. This is - // equivalent, because regardless of which pointer is lower, one of them - // will always came after the other, as long as the underlying objects aren't - // disjoint. We do this so that the rest of BasicAA does not have to deal - // with accesses before the base pointer, and to improve cache utilization by - // merging equivalent states. - if (V1Size.mayBeBeforePointer() || V2Size.mayBeBeforePointer()) { - V1Size = LocationSize::afterPointer(); - V2Size = LocationSize::afterPointer(); - } - + // If one the accesses may be before the accessed pointer, canonicalize this + // by using unknown after-pointer sizes for both accesses. This is + // equivalent, because regardless of which pointer is lower, one of them + // will always came after the other, as long as the underlying objects aren't + // disjoint. We do this so that the rest of BasicAA does not have to deal + // with accesses before the base pointer, and to improve cache utilization by + // merging equivalent states. + if (V1Size.mayBeBeforePointer() || V2Size.mayBeBeforePointer()) { + V1Size = LocationSize::afterPointer(); + V2Size = LocationSize::afterPointer(); + } + // Check the cache before climbing up use-def chains. This also terminates // otherwise infinitely recursive queries. AAQueryInfo::LocPair Locs(MemoryLocation(V1, V1Size, V1AAInfo), MemoryLocation(V2, V2Size, V2AAInfo)); if (V1 > V2) std::swap(Locs.first, Locs.second); - const auto &Pair = AAQI.AliasCache.try_emplace( - Locs, AAQueryInfo::CacheEntry{NoAlias, 0}); - if (!Pair.second) { - auto &Entry = Pair.first->second; - if (!Entry.isDefinitive()) { - // Remember that we used an assumption. - ++Entry.NumAssumptionUses; - ++AAQI.NumAssumptionUses; - } - return Entry.Result; - } - - int OrigNumAssumptionUses = AAQI.NumAssumptionUses; - unsigned OrigNumAssumptionBasedResults = AAQI.AssumptionBasedResults.size(); - AliasResult Result = aliasCheckRecursive(V1, V1Size, V1AAInfo, V2, V2Size, - V2AAInfo, AAQI, O1, O2); - - auto It = AAQI.AliasCache.find(Locs); - assert(It != AAQI.AliasCache.end() && "Must be in cache"); - auto &Entry = It->second; - - // Check whether a NoAlias assumption has been used, but disproven. - bool AssumptionDisproven = Entry.NumAssumptionUses > 0 && Result != NoAlias; - if (AssumptionDisproven) - Result = MayAlias; - - // This is a definitive result now, when considered as a root query. - AAQI.NumAssumptionUses -= Entry.NumAssumptionUses; - Entry.Result = Result; - Entry.NumAssumptionUses = -1; - - // If the assumption has been disproven, remove any results that may have - // been based on this assumption. Do this after the Entry updates above to - // avoid iterator invalidation. - if (AssumptionDisproven) - while (AAQI.AssumptionBasedResults.size() > OrigNumAssumptionBasedResults) - AAQI.AliasCache.erase(AAQI.AssumptionBasedResults.pop_back_val()); - - // The result may still be based on assumptions higher up in the chain. - // Remember it, so it can be purged from the cache later. - if (OrigNumAssumptionUses != AAQI.NumAssumptionUses && Result != MayAlias) - AAQI.AssumptionBasedResults.push_back(Locs); - return Result; -} - -AliasResult BasicAAResult::aliasCheckRecursive( - const Value *V1, LocationSize V1Size, const AAMDNodes &V1AAInfo, - const Value *V2, LocationSize V2Size, const AAMDNodes &V2AAInfo, - AAQueryInfo &AAQI, const Value *O1, const Value *O2) { + const auto &Pair = AAQI.AliasCache.try_emplace( + Locs, AAQueryInfo::CacheEntry{NoAlias, 0}); + if (!Pair.second) { + auto &Entry = Pair.first->second; + if (!Entry.isDefinitive()) { + // Remember that we used an assumption. + ++Entry.NumAssumptionUses; + ++AAQI.NumAssumptionUses; + } + return Entry.Result; + } + + int OrigNumAssumptionUses = AAQI.NumAssumptionUses; + unsigned OrigNumAssumptionBasedResults = AAQI.AssumptionBasedResults.size(); + AliasResult Result = aliasCheckRecursive(V1, V1Size, V1AAInfo, V2, V2Size, + V2AAInfo, AAQI, O1, O2); + + auto It = AAQI.AliasCache.find(Locs); + assert(It != AAQI.AliasCache.end() && "Must be in cache"); + auto &Entry = It->second; + + // Check whether a NoAlias assumption has been used, but disproven. + bool AssumptionDisproven = Entry.NumAssumptionUses > 0 && Result != NoAlias; + if (AssumptionDisproven) + Result = MayAlias; + + // This is a definitive result now, when considered as a root query. + AAQI.NumAssumptionUses -= Entry.NumAssumptionUses; + Entry.Result = Result; + Entry.NumAssumptionUses = -1; + + // If the assumption has been disproven, remove any results that may have + // been based on this assumption. Do this after the Entry updates above to + // avoid iterator invalidation. + if (AssumptionDisproven) + while (AAQI.AssumptionBasedResults.size() > OrigNumAssumptionBasedResults) + AAQI.AliasCache.erase(AAQI.AssumptionBasedResults.pop_back_val()); + + // The result may still be based on assumptions higher up in the chain. + // Remember it, so it can be purged from the cache later. + if (OrigNumAssumptionUses != AAQI.NumAssumptionUses && Result != MayAlias) + AAQI.AssumptionBasedResults.push_back(Locs); + return Result; +} + +AliasResult BasicAAResult::aliasCheckRecursive( + const Value *V1, LocationSize V1Size, const AAMDNodes &V1AAInfo, + const Value *V2, LocationSize V2Size, const AAMDNodes &V2AAInfo, + AAQueryInfo &AAQI, const Value *O1, const Value *O2) { if (const GEPOperator *GV1 = dyn_cast<GEPOperator>(V1)) { AliasResult Result = aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2, AAQI); - if (Result != MayAlias) - return Result; - } else if (const GEPOperator *GV2 = dyn_cast<GEPOperator>(V2)) { - AliasResult Result = - aliasGEP(GV2, V2Size, V2AAInfo, V1, V1Size, V1AAInfo, O2, O1, AAQI); - if (Result != MayAlias) + if (Result != MayAlias) return Result; + } else if (const GEPOperator *GV2 = dyn_cast<GEPOperator>(V2)) { + AliasResult Result = + aliasGEP(GV2, V2Size, V2AAInfo, V1, V1Size, V1AAInfo, O2, O1, AAQI); + if (Result != MayAlias) + return Result; } if (const PHINode *PN = dyn_cast<PHINode>(V1)) { AliasResult Result = - aliasPHI(PN, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, AAQI); - if (Result != MayAlias) - return Result; - } else if (const PHINode *PN = dyn_cast<PHINode>(V2)) { - AliasResult Result = - aliasPHI(PN, V2Size, V2AAInfo, V1, V1Size, V1AAInfo, AAQI); - if (Result != MayAlias) - return Result; + aliasPHI(PN, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, AAQI); + if (Result != MayAlias) + return Result; + } else if (const PHINode *PN = dyn_cast<PHINode>(V2)) { + AliasResult Result = + aliasPHI(PN, V2Size, V2AAInfo, V1, V1Size, V1AAInfo, AAQI); + if (Result != MayAlias) + return Result; } if (const SelectInst *S1 = dyn_cast<SelectInst>(V1)) { AliasResult Result = - aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, AAQI); - if (Result != MayAlias) - return Result; - } else if (const SelectInst *S2 = dyn_cast<SelectInst>(V2)) { - AliasResult Result = - aliasSelect(S2, V2Size, V2AAInfo, V1, V1Size, V1AAInfo, AAQI); - if (Result != MayAlias) - return Result; + aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, AAQI); + if (Result != MayAlias) + return Result; + } else if (const SelectInst *S2 = dyn_cast<SelectInst>(V2)) { + AliasResult Result = + aliasSelect(S2, V2Size, V2AAInfo, V1, V1Size, V1AAInfo, AAQI); + if (Result != MayAlias) + return Result; } // If both pointers are pointing into the same object and one of them // accesses the entire object, then the accesses must overlap in some way. - if (O1 == O2) { - bool NullIsValidLocation = NullPointerIsDefined(&F); + if (O1 == O2) { + bool NullIsValidLocation = NullPointerIsDefined(&F); if (V1Size.isPrecise() && V2Size.isPrecise() && (isObjectSize(O1, V1Size.getValue(), DL, TLI, NullIsValidLocation) || - isObjectSize(O2, V2Size.getValue(), DL, TLI, NullIsValidLocation))) - return PartialAlias; - } + isObjectSize(O2, V2Size.getValue(), DL, TLI, NullIsValidLocation))) + return PartialAlias; + } - return MayAlias; + return MayAlias; } /// Check whether two Values can be considered equivalent. @@ -1760,7 +1760,7 @@ void BasicAAResult::GetIndexDifference( // If we didn't consume this entry, add it to the end of the Dest list. if (!!Scale) { - VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale, Src[i].CxtI}; + VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale, Src[i].CxtI}; Dest.push_back(Entry); } } @@ -1770,8 +1770,8 @@ bool BasicAAResult::constantOffsetHeuristic( const SmallVectorImpl<VariableGEPIndex> &VarIndices, LocationSize MaybeV1Size, LocationSize MaybeV2Size, const APInt &BaseOffset, AssumptionCache *AC, DominatorTree *DT) { - if (VarIndices.size() != 2 || !MaybeV1Size.hasValue() || - !MaybeV2Size.hasValue()) + if (VarIndices.size() != 2 || !MaybeV1Size.hasValue() || + !MaybeV2Size.hasValue()) return false; const uint64_t V1Size = MaybeV1Size.getValue(); @@ -1831,12 +1831,12 @@ bool BasicAAResult::constantOffsetHeuristic( AnalysisKey BasicAA::Key; BasicAAResult BasicAA::run(Function &F, FunctionAnalysisManager &AM) { - auto &TLI = AM.getResult<TargetLibraryAnalysis>(F); - auto &AC = AM.getResult<AssumptionAnalysis>(F); - auto *DT = &AM.getResult<DominatorTreeAnalysis>(F); - auto *LI = AM.getCachedResult<LoopAnalysis>(F); - auto *PV = AM.getCachedResult<PhiValuesAnalysis>(F); - return BasicAAResult(F.getParent()->getDataLayout(), F, TLI, AC, DT, LI, PV); + auto &TLI = AM.getResult<TargetLibraryAnalysis>(F); + auto &AC = AM.getResult<AssumptionAnalysis>(F); + auto *DT = &AM.getResult<DominatorTreeAnalysis>(F); + auto *LI = AM.getCachedResult<LoopAnalysis>(F); + auto *PV = AM.getCachedResult<PhiValuesAnalysis>(F); + return BasicAAResult(F.getParent()->getDataLayout(), F, TLI, AC, DT, LI, PV); } BasicAAWrapperPass::BasicAAWrapperPass() : FunctionPass(ID) { @@ -1878,9 +1878,9 @@ bool BasicAAWrapperPass::runOnFunction(Function &F) { void BasicAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); - AU.addRequiredTransitive<AssumptionCacheTracker>(); - AU.addRequiredTransitive<DominatorTreeWrapperPass>(); - AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>(); + AU.addRequiredTransitive<AssumptionCacheTracker>(); + AU.addRequiredTransitive<DominatorTreeWrapperPass>(); + AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>(); AU.addUsedIfAvailable<PhiValuesWrapperPass>(); } |