[PATCH] D133996: Add a cache for DL.getTypeAllocSize() to BasicAA.
Justin Lebar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 17:16:44 PDT 2022
jlebar created this revision.
jlebar added a reviewer: asbirlea.
Herald added subscribers: jeroen.dobbelaere, hiraditya.
Herald added a project: All.
jlebar requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
getTypeAllocSize is surprisingly expensive. In my (private, sorry)
testcase, we spend 400ms in getTypeAllocSize out of a total of 3s in
BasicAA. After this change, this goes to 0, and I see no measurable
overhead from the hashtable lookup. Therefore this is a >1.1x speedup
to BasicAA, in my test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133996
Files:
llvm/include/llvm/Analysis/BasicAliasAnalysis.h
llvm/lib/Analysis/BasicAliasAnalysis.cpp
Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -508,6 +508,13 @@
}
};
+TypeSize BasicAAResult::GetTypeAllocSize(Type *Ty) {
+ auto it_and_inserted = TypeAllocSizeCache.insert({Ty, TypeSize::Fixed(0)});
+ if (it_and_inserted.second) {
+ it_and_inserted.first->second = DL.getTypeAllocSize(Ty);
+ }
+ return it_and_inserted.first->second;
+}
/// If V is a symbolic pointer expression, decompose it into a base pointer
/// with a constant offset and a number of scaled symbolic offsets.
@@ -527,6 +534,7 @@
unsigned MaxIndexSize = DL.getMaxIndexSizeInBits();
DecomposedGEP Decomposed;
Decomposed.Offset = APInt(MaxIndexSize, 0);
+
do {
// See if this is a bitcast or GEP.
const Operator *Op = dyn_cast<Operator>(V);
@@ -611,7 +619,7 @@
continue;
// Don't attempt to analyze GEPs if the scalable index is not zero.
- TypeSize AllocTypeSize = DL.getTypeAllocSize(GTI.getIndexedType());
+ TypeSize AllocTypeSize = GetTypeAllocSize(GTI.getIndexedType());
if (AllocTypeSize.isScalable()) {
Decomposed.Base = V;
return Decomposed;
@@ -622,7 +630,7 @@
continue;
}
- TypeSize AllocTypeSize = DL.getTypeAllocSize(GTI.getIndexedType());
+ TypeSize AllocTypeSize = GetTypeAllocSize(GTI.getIndexedType());
if (AllocTypeSize.isScalable()) {
Decomposed.Base = V;
return Decomposed;
Index: llvm/include/llvm/Analysis/BasicAliasAnalysis.h
===================================================================
--- llvm/include/llvm/Analysis/BasicAliasAnalysis.h
+++ llvm/include/llvm/Analysis/BasicAliasAnalysis.h
@@ -113,9 +113,15 @@
/// Tracks instructions visited by pointsToConstantMemory.
SmallPtrSet<const Value *, 16> Visited;
- static DecomposedGEP
- DecomposeGEPExpression(const Value *V, const DataLayout &DL,
- AssumptionCache *AC, DominatorTree *DT);
+ // Cache around DL.getTypeAllocSize(), which is surprisingly expensive.
+ DenseMap<const Type *, TypeSize> TypeAllocSizeCache;
+
+ // Returns DL.getTypeAllocSize() and inserts it into the cache if it's not
+ // present.
+ TypeSize GetTypeAllocSize(Type *Ty);
+
+ DecomposedGEP DecomposeGEPExpression(const Value *V, const DataLayout &DL,
+ AssumptionCache *AC, DominatorTree *DT);
/// A Heuristic for aliasGEP that searches for a constant offset
/// between the variables.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133996.460561.patch
Type: text/x-patch
Size: 2623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220916/693b8c33/attachment.bin>
More information about the llvm-commits
mailing list