[llvm] dd13744 - Revert "[BasicAliasAnalysis] Remove isMallocOrCallocLikeFn"
Bryce Wilson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 14 14:43:33 PST 2022
Author: Bryce Wilson
Date: 2022-01-14T14:42:53-08:00
New Revision: dd13744bfb0a85851dbd554138e25767bb0f35b6
URL: https://github.com/llvm/llvm-project/commit/dd13744bfb0a85851dbd554138e25767bb0f35b6
DIFF: https://github.com/llvm/llvm-project/commit/dd13744bfb0a85851dbd554138e25767bb0f35b6.diff
LOG: Revert "[BasicAliasAnalysis] Remove isMallocOrCallocLikeFn"
This reverts commit 1f2cfc4fdc1eefb2c5f562c77a5fe7e916bbf670.
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Transforms/GVN/nonescaping-malloc.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 9485565bb57b7..fa9ccb095a21d 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -996,6 +996,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;
+ }
+
// The semantics of memcpy intrinsics either exactly overlap or do not
// overlap, i.e., source and destination of any given memcpy are either
// no-alias or must-alias.
diff --git a/llvm/test/Transforms/GVN/nonescaping-malloc.ll b/llvm/test/Transforms/GVN/nonescaping-malloc.ll
index 9eaf54c7a3d6c..fd61835e14a40 100644
--- a/llvm/test/Transforms/GVN/nonescaping-malloc.ll
+++ b/llvm/test/Transforms/GVN/nonescaping-malloc.ll
@@ -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)
@@ -66,7 +66,7 @@ bb4.i: ; preds = %entry
%tmp4.i.i = sub i32 %tmp1.i.i, %tmp3.i.i
%tmp5.i.i = add i32 %tmp4.i.i, 17
%tmp8.i.i = zext i32 %tmp5.i.i to i64
- %tmp.i20.i.i = tail call noalias i8* @malloc(i64 %tmp8.i.i) nounwind inaccessiblememonly
+ %tmp.i20.i.i = tail call noalias i8* @malloc(i64 %tmp8.i.i) nounwind
%tmp10.i.i = bitcast i8* %tmp.i20.i.i to %"struct.llvm::StringMapEntry<void*>"*
%tmp12.i.i = icmp eq i8* %tmp.i20.i.i, null
br i1 %tmp12.i.i, label %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i, label %bb.i.i
More information about the llvm-commits
mailing list