diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-09-29 22:58:30 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-09-29 23:32:15 +0200 |
commit | 45288edb6500da98e9a3f133da0f14d0f7586c5b (patch) | |
tree | f99ae63b750bdada6decb219d09642babaf31105 /llvm/lib/Analysis/BasicAliasAnalysis.cpp | |
parent | 940755515da6254abc3af6e21375fde8c2a8f3b4 (diff) | |
download | llvm-45288edb6500da98e9a3f133da0f14d0f7586c5b.zip llvm-45288edb6500da98e9a3f133da0f14d0f7586c5b.tar.gz llvm-45288edb6500da98e9a3f133da0f14d0f7586c5b.tar.bz2 |
[BasicAA] Pass whole DecomposedGEP to subtraction API (NFC)
Rather than separately handling subtraction of offset and variable
indices, make this one operation. Also rewrite the implementation
to use range-based for loops.
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 50 |
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); } } } |