aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp50
1 files changed, 21 insertions, 29 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 5e60cbe..f80a44f 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1096,8 +1096,7 @@ AliasResult BasicAAResult::aliasGEP(
// Subtract the GEP2 pointer from the GEP1 pointer to find out their
// symbolic difference.
- DecompGEP1.Offset -= DecompGEP2.Offset;
- GetIndexDifference(DecompGEP1.VarIndices, DecompGEP2.VarIndices);
+ subtractDecomposedGEPs(DecompGEP1, DecompGEP2);
// If an inbounds GEP would have to start from an out of bounds address
// for the two to alias, then we can assume noalias.
@@ -1729,43 +1728,36 @@ bool BasicAAResult::isValueEqualInPotentialCycles(const Value *V,
}
/// Computes the symbolic difference between two de-composed GEPs.
-///
-/// Dest and Src are the variable indices from two decomposed GetElementPtr
-/// instructions GEP1 and GEP2 which have common base pointers.
-void BasicAAResult::GetIndexDifference(
- SmallVectorImpl<VariableGEPIndex> &Dest,
- const SmallVectorImpl<VariableGEPIndex> &Src) {
- if (Src.empty())
- return;
-
- for (unsigned i = 0, e = Src.size(); i != e; ++i) {
- const Value *V = Src[i].V;
- unsigned ZExtBits = Src[i].ZExtBits, SExtBits = Src[i].SExtBits;
- APInt Scale = Src[i].Scale;
-
+void BasicAAResult::subtractDecomposedGEPs(DecomposedGEP &DestGEP,
+ const DecomposedGEP &SrcGEP) {
+ DestGEP.Offset -= SrcGEP.Offset;
+ for (const VariableGEPIndex &Src : SrcGEP.VarIndices) {
// Find V in Dest. This is N^2, but pointer indices almost never have more
// than a few variable indexes.
- for (unsigned j = 0, e = Dest.size(); j != e; ++j) {
- if (!isValueEqualInPotentialCycles(Dest[j].V, V) ||
- Dest[j].ZExtBits != ZExtBits || Dest[j].SExtBits != SExtBits)
+ bool Found = false;
+ for (auto I : enumerate(DestGEP.VarIndices)) {
+ VariableGEPIndex &Dest = I.value();
+ if (!isValueEqualInPotentialCycles(Dest.V, Src.V) ||
+ Dest.ZExtBits != Src.ZExtBits || Dest.SExtBits != Src.SExtBits)
continue;
// If we found it, subtract off Scale V's from the entry in Dest. If it
// goes to zero, remove the entry.
- if (Dest[j].Scale != Scale) {
- Dest[j].Scale -= Scale;
- Dest[j].IsNSW = false;
- } else
- Dest.erase(Dest.begin() + j);
- Scale = 0;
+ if (Dest.Scale != Src.Scale) {
+ Dest.Scale -= Src.Scale;
+ Dest.IsNSW = false;
+ } else {
+ DestGEP.VarIndices.erase(DestGEP.VarIndices.begin() + I.index());
+ }
+ Found = true;
break;
}
// 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, Src[i].IsNSW};
- Dest.push_back(Entry);
+ if (!Found) {
+ VariableGEPIndex Entry = {Src.V, Src.ZExtBits, Src.SExtBits,
+ -Src.Scale, Src.CxtI, Src.IsNSW};
+ DestGEP.VarIndices.push_back(Entry);
}
}
}