[PATCH] D117180: [BasicAliasAnalysis] Switch from isMallocOrCallocLikeFn to onlyAccessesInaccessibleMemory

Bryce Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 21:00:39 PST 2022


Bryce-MW updated this revision to Diff 399542.
Bryce-MW added a comment.

- malloc is inaccessiblememonly


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117180/new/

https://reviews.llvm.org/D117180

Files:
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/test/Transforms/GVN/nonescaping-malloc.ll


Index: llvm/test/Transforms/GVN/nonescaping-malloc.ll
===================================================================
--- llvm/test/Transforms/GVN/nonescaping-malloc.ll
+++ llvm/test/Transforms/GVN/nonescaping-malloc.ll
@@ -35,7 +35,7 @@
 
 declare i64 @strlen(i8* nocapture) nounwind readonly
 
-declare noalias i8* @malloc(i64) nounwind
+declare noalias i8* @malloc(i64) nounwind inaccessiblememonly
 
 declare i32 @_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefE(%"struct.llvm::StringMapImpl"*, i64, i64)
 
@@ -66,7 +66,7 @@
   %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
+  %tmp.i20.i.i = tail call noalias i8* @malloc(i64 %tmp8.i.i) nounwind inaccessiblememonly
   %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
Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -996,13 +996,9 @@
     }
   }
 
-  // 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)) {
+  // TODO: Consider using inaccessiblememorargmemonly  to allow for functions
+  // like realloc and strdup which access only their arguments as well.
+  if (Call->onlyAccessesInaccessibleMemory()) {
     // Be conservative if the accessed pointer may alias the allocation -
     // fallback to the generic handling below.
     if (getBestAAResults().alias(MemoryLocation::getBeforeOrAfter(Call), Loc,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117180.399542.patch
Type: text/x-patch
Size: 2192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220113/6a793d7f/attachment.bin>


More information about the llvm-commits mailing list