[PATCH] D9398: llvm.noalias - GetUnderlyingObjects to optionally collect noalias calls

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 14:53:15 PDT 2016


hfinkel updated this revision to Diff 73348.
hfinkel added a comment.

Rebased


https://reviews.llvm.org/D9398

Files:
  include/llvm/Analysis/ValueTracking.h
  lib/Analysis/ValueTracking.cpp


Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -3052,7 +3052,8 @@
 }
 
 Value *llvm::GetUnderlyingObject(Value *V, const DataLayout &DL,
-                                 unsigned MaxLookup) {
+                                 unsigned MaxLookup,
+                                 SmallVectorImpl<Instruction *> *NoAlias) {
   if (!V->getType()->isPointerTy())
     return V;
   for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
@@ -3066,6 +3067,12 @@
         return V;
       V = GA->getAliasee();
     } else {
+      if (auto *I = dyn_cast<IntrinsicInst>(V))
+        if (I->getIntrinsicID() == Intrinsic::noalias) {
+          if (NoAlias)
+            NoAlias->push_back(I);
+        }
+
       if (auto CS = CallSite(V))
         if (Value *RV = CS.getReturnedArgOperand()) {
           V = RV;
@@ -3089,13 +3096,14 @@
 
 void llvm::GetUnderlyingObjects(Value *V, SmallVectorImpl<Value *> &Objects,
                                 const DataLayout &DL, LoopInfo *LI,
-                                unsigned MaxLookup) {
+                                unsigned MaxLookup,
+                                SmallVectorImpl<Instruction *> *NoAlias) {
   SmallPtrSet<Value *, 4> Visited;
   SmallVector<Value *, 4> Worklist;
   Worklist.push_back(V);
   do {
     Value *P = Worklist.pop_back_val();
-    P = GetUnderlyingObject(P, DL, MaxLookup);
+    P = GetUnderlyingObject(P, DL, MaxLookup, NoAlias);
 
     if (!Visited.insert(P).second)
       continue;
Index: include/llvm/Analysis/ValueTracking.h
===================================================================
--- include/llvm/Analysis/ValueTracking.h
+++ include/llvm/Analysis/ValueTracking.h
@@ -222,13 +222,16 @@
   /// the specified value, returning the original object being addressed. Note
   /// that the returned value has pointer type if the specified value does. If
   /// the MaxLookup value is non-zero, it limits the number of instructions to
-  /// be stripped off.
+  /// be stripped off. If a NoAlias vector is provided, it is filled with any
+  /// llvm.noalias intrinsics looked through to find the underlying object.
   Value *GetUnderlyingObject(Value *V, const DataLayout &DL,
-                             unsigned MaxLookup = 6);
-  static inline const Value *GetUnderlyingObject(const Value *V,
-                                                 const DataLayout &DL,
-                                                 unsigned MaxLookup = 6) {
-    return GetUnderlyingObject(const_cast<Value *>(V), DL, MaxLookup);
+                             unsigned MaxLookup = 6,
+                             SmallVectorImpl<Instruction *> *NoAlias = nullptr);
+  static inline
+  const Value *GetUnderlyingObject(const Value *V,
+                 const DataLayout &DL, unsigned MaxLookup = 6,
+                 SmallVectorImpl<Instruction *> *NoAlias = nullptr) {
+    return GetUnderlyingObject(const_cast<Value *>(V), DL, MaxLookup, NoAlias);
   }
 
   /// \brief This method is similar to GetUnderlyingObject except that it can
@@ -258,10 +261,13 @@
   ///
   /// Since A[i] and A[i-1] are independent pointers, getUnderlyingObjects
   /// should not assume that Curr and Prev share the same underlying object thus
-  /// it shouldn't look through the phi above.
+  /// it shouldn't look through the phi above. If a NoAlias vector is provided,
+  /// it is filled with any llvm.noalias intrinsics looked through to find the
+  /// underlying objects.
   void GetUnderlyingObjects(Value *V, SmallVectorImpl<Value *> &Objects,
                             const DataLayout &DL, LoopInfo *LI = nullptr,
-                            unsigned MaxLookup = 6);
+                            unsigned MaxLookup = 6,
+                            SmallVectorImpl<Instruction *> *NoAlias = nullptr);
 
   /// Return true if the only users of this pointer are lifetime markers.
   bool onlyUsedByLifetimeMarkers(const Value *V);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9398.73348.patch
Type: text/x-patch
Size: 4059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/8c60669d/attachment.bin>


More information about the llvm-commits mailing list