diff options
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp | 14 |
2 files changed, 31 insertions, 18 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index f9ecbc04326..6d4ac96ad37 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1001,9 +1001,9 @@ ModRefInfo BasicAAResult::getModRefInfo(ImmutableCallSite CS1, /// Provide ad-hoc rules to disambiguate accesses through two GEP operators, /// both having the exact same pointer operand. static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1, - LocationSize V1Size, + LocationSize MaybeV1Size, const GEPOperator *GEP2, - LocationSize V2Size, + LocationSize MaybeV2Size, const DataLayout &DL) { assert(GEP1->getPointerOperand()->stripPointerCastsAndInvariantGroups() == GEP2->getPointerOperand()->stripPointerCastsAndInvariantGroups() && @@ -1019,10 +1019,13 @@ static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1, // If we don't know the size of the accesses through both GEPs, we can't // determine whether the struct fields accessed can't alias. - if (V1Size == MemoryLocation::UnknownSize || - V2Size == MemoryLocation::UnknownSize) + if (MaybeV1Size == MemoryLocation::UnknownSize || + MaybeV2Size == MemoryLocation::UnknownSize) return MayAlias; + const uint64_t V1Size = MaybeV1Size; + const uint64_t V2Size = MaybeV2Size; + ConstantInt *C1 = dyn_cast<ConstantInt>(GEP1->getOperand(GEP1->getNumOperands() - 1)); ConstantInt *C2 = @@ -1179,11 +1182,14 @@ static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1, // than (%alloca - 1), and so is not inbounds, a contradiction. bool BasicAAResult::isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp, const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompObject, - LocationSize ObjectAccessSize) { + LocationSize MaybeObjectAccessSize) { // If the object access size is unknown, or the GEP isn't inbounds, bail. - if (ObjectAccessSize == MemoryLocation::UnknownSize || !GEPOp->isInBounds()) + if (MaybeObjectAccessSize == MemoryLocation::UnknownSize || + !GEPOp->isInBounds()) return false; + const uint64_t ObjectAccessSize = MaybeObjectAccessSize; + // We need the object to be an alloca or a globalvariable, and want to know // the offset of the pointer from the object precisely, so no variable // indices are allowed. @@ -1418,7 +1424,9 @@ BasicAAResult::aliasGEP(const GEPOperator *GEP1, LocationSize V1Size, // If we know all the variables are positive, then GEP1 >= GEP1BasePtr. // If GEP1BasePtr > V2 (GEP1BaseOffset > 0) then we know the pointers // don't alias if V2Size can fit in the gap between V2 and GEP1BasePtr. - if (AllPositive && GEP1BaseOffset > 0 && V2Size <= (uint64_t)GEP1BaseOffset) + if (AllPositive && GEP1BaseOffset > 0 && + V2Size != MemoryLocation::UnknownSize && + V2Size <= (uint64_t)GEP1BaseOffset) return NoAlias; if (constantOffsetHeuristic(DecompGEP1.VarIndices, V1Size, V2Size, @@ -1853,13 +1861,16 @@ void BasicAAResult::GetIndexDifference( } bool BasicAAResult::constantOffsetHeuristic( - const SmallVectorImpl<VariableGEPIndex> &VarIndices, LocationSize V1Size, - LocationSize V2Size, int64_t BaseOffset, AssumptionCache *AC, - DominatorTree *DT) { - if (VarIndices.size() != 2 || V1Size == MemoryLocation::UnknownSize || - V2Size == MemoryLocation::UnknownSize) + const SmallVectorImpl<VariableGEPIndex> &VarIndices, + LocationSize MaybeV1Size, LocationSize MaybeV2Size, int64_t BaseOffset, + AssumptionCache *AC, DominatorTree *DT) { + if (VarIndices.size() != 2 || MaybeV1Size == MemoryLocation::UnknownSize || + MaybeV2Size == MemoryLocation::UnknownSize) return false; + const uint64_t V1Size = MaybeV1Size; + const uint64_t V2Size = MaybeV2Size; + const VariableGEPIndex &Var0 = VarIndices[0], &Var1 = VarIndices[1]; if (Var0.ZExtBits != Var1.ZExtBits || Var0.SExtBits != Var1.SExtBits || diff --git a/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp b/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp index 18ea37fd7a8..db350e2c22f 100644 --- a/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp +++ b/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp @@ -515,10 +515,9 @@ CFLAndersAAResult::FunctionInfo::getAttrs(const Value *V) const { return None; } -bool CFLAndersAAResult::FunctionInfo::mayAlias(const Value *LHS, - LocationSize LHSSize, - const Value *RHS, - LocationSize RHSSize) const { +bool CFLAndersAAResult::FunctionInfo::mayAlias( + const Value *LHS, LocationSize MaybeLHSSize, const Value *RHS, + LocationSize MaybeRHSSize) const { assert(LHS && RHS); // Check if we've seen LHS and RHS before. Sometimes LHS or RHS can be created @@ -558,10 +557,13 @@ bool CFLAndersAAResult::FunctionInfo::mayAlias(const Value *LHS, if (RangePair.first != RangePair.second) { // Be conservative about UnknownSize - if (LHSSize == MemoryLocation::UnknownSize || - RHSSize == MemoryLocation::UnknownSize) + if (MaybeLHSSize == MemoryLocation::UnknownSize || + MaybeRHSSize == MemoryLocation::UnknownSize) return true; + const uint64_t LHSSize = MaybeLHSSize; + const uint64_t RHSSize = MaybeRHSSize; + for (const auto &OVal : make_range(RangePair)) { // Be conservative about UnknownOffset if (OVal.Offset == UnknownOffset) |