Skip to content

Commit

Permalink
Revert "[BasicAA] Remove unneeded special case for malloc/calloc"
Browse files Browse the repository at this point in the history
This reverts commit 9b1e007.

Nikic reported in commit thread that I had forgotten history here, and that a) we'd tried this before, and b) had to revert due to an unexpected codegen impact.  Current measurements confirm the same issue still exists.
  • Loading branch information
preames committed May 18, 2022
1 parent 4273e61 commit f7988d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,20 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call,
}
}

// If the call is malloc/calloc like, we can assume that it doesn't
// modify any IR visible value. This is only valid because we assume these
// routines do not read values visible in the IR. TODO: Consider special
// casing realloc and strdup routines which access only their arguments as
// well. Or alternatively, replace all of this with inaccessiblememonly once
// that's implemented fully.
if (isMallocOrCallocLikeFn(Call, &TLI)) {
// Be conservative if the accessed pointer may alias the allocation -
// fallback to the generic handling below.
if (getBestAAResults().alias(MemoryLocation::getBeforeOrAfter(Call), Loc,
AAQI) == AliasResult::NoAlias)
return ModRefInfo::NoModRef;
}

// Ideally, there should be no need to special case for memcpy/memove
// intrinsics here since general machinery (based on memory attributes) should
// already handle it just fine. Unfortunately, it doesn't due to deficiency in
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/GVN/nonescaping-malloc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ entry:

declare i64 @strlen(i8* nocapture) nounwind readonly

declare noalias i8* @malloc(i64) nounwind inaccessiblememonly
declare noalias i8* @malloc(i64) nounwind

declare i32 @_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefE(%"struct.llvm::StringMapImpl"*, i64, i64)

Expand Down

0 comments on commit f7988d0

Please sign in to comment.