Skip to content

Commit

Permalink
[MemoryBuiltins] Don't query TLI for non-pointer functions (NFC)
Browse files Browse the repository at this point in the history
Fetching allocation data for calls is a rather hot operation, and
TLI lookups are slow. We can greatly reduce the number of calls
for which TLI is queried by checking that they return a pointer
value first, as this is a requirement for allocation functions
anyway.
  • Loading branch information
nikic committed Jul 21, 2022
1 parent ea623af commit 235fb60
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Analysis/MemoryBuiltins.cpp
Expand Up @@ -179,6 +179,11 @@ static const Function *getCalledFunction(const Value *V,
static Optional<AllocFnsTy>
getAllocationDataForFunction(const Function *Callee, AllocType AllocTy,
const TargetLibraryInfo *TLI) {
// Don't perform a slow TLI lookup, if this function doesn't return a pointer
// and thus can't be an allocation function.
if (!Callee->getReturnType()->isPointerTy())
return None;

// Make sure that the function is available.
LibFunc TLIFn;
if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn))
Expand Down

0 comments on commit 235fb60

Please sign in to comment.