[PATCH] D117084: [CFLGraph] Change isMallocOrCallocLikeFn to isNoAliasCall now that allocation functions must be marked noalias

Bryce Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 11 20:55:57 PST 2022


Bryce-MW created this revision.
Bryce-MW added a reviewer: reames.
Herald added subscribers: jeroen.dobbelaere, hiraditya.
Bryce-MW requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Allocation functions must now be marked noalias and any function marked noalias does not introduce aliases. The if condition below like 461 will now always be true because Fn->returnDoesNotAlias() returns the same result as isNoAliasCall(&Call). Since we return early if isNoAliasCall returns true, it will always be false at the point of the condition. I'm happy to restore that condition for safety if wanted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117084

Files:
  llvm/lib/Analysis/CFLGraph.h


Index: llvm/lib/Analysis/CFLGraph.h
===================================================================
--- llvm/lib/Analysis/CFLGraph.h
+++ llvm/lib/Analysis/CFLGraph.h
@@ -429,12 +429,10 @@
       if (Call.getType()->isPointerTy())
         addNode(&Call);
 
-      // Check if Inst is a call to a library function that
-      // allocates/deallocates on the heap. Those kinds of functions do not
-      // introduce any aliases.
-      // TODO: address other common library functions such as realloc(),
-      // strdup(), etc.
-      if (isMallocOrCallocLikeFn(&Call, &TLI) || isFreeCall(&Call, &TLI))
+      // Check if Inst is a call to a function that is annotated noalias
+      // (including allocation functions) or a library function that frees
+      // memory. Those kinds of functions do not introduce any aliases.
+      if (isNoAliasCall(&Call) || isFreeCall(&Call, &TLI))
         return;
 
       // TODO: Add support for noalias args/all the other fun function
@@ -461,11 +459,11 @@
         }
 
       if (Call.getType()->isPointerTy()) {
-        auto *Fn = Call.getCalledFunction();
-        if (Fn == nullptr || !Fn->returnDoesNotAlias())
-          // No need to call addNode() since we've added Inst at the
-          // beginning of this function and we know it is not a global.
-          Graph.addAttr(InstantiatedValue{&Call, 0}, getAttrUnknown());
+        // Since we checked isNoAliasCall and returned early if true, we don't
+        // need to confirm that it is false now.
+        // No need to call addNode() since we've added Inst at the
+        // beginning of this function and we know it is not a global.
+        Graph.addAttr(InstantiatedValue{&Call, 0}, getAttrUnknown());
       }
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117084.399191.patch
Type: text/x-patch
Size: 1736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220112/43af71d1/attachment.bin>


More information about the llvm-commits mailing list