aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2022-05-18 07:33:39 -0700
committerPhilip Reames <listmail@philipreames.com>2022-05-18 07:35:27 -0700
commitf7988d08a8bf11e551e720ba72c90c42d6756ece (patch)
treefc3523e856942e2f9c93321596b5948a339ab703 /llvm/lib/Analysis/BasicAliasAnalysis.cpp
parent4273e616e573f4854e9c659c2e6d8a31f3e3c595 (diff)
downloadllvm-f7988d08a8bf11e551e720ba72c90c42d6756ece.zip
llvm-f7988d08a8bf11e551e720ba72c90c42d6756ece.tar.gz
llvm-f7988d08a8bf11e551e720ba72c90c42d6756ece.tar.bz2
Revert "[BasicAA] Remove unneeded special case for malloc/calloc"
This reverts commit 9b1e00738c5ddba681e17e5cb7c260d9afc4c3a7. 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.
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 63d5842..cfb3468 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -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