[PATCH] D9401: llvm.noalias - The AA implementaton

Jeroen Dobbelaere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 7 06:20:19 PDT 2017


jeroen.dobbelaere added a comment.

Hi Hal, I found an issue with this part when analyzing two pointers that are 'derived from each other', but are used in different loops.
Following code would go wrong:

  int* restrict p=malloc(sizeof(int)*20);
  int i;
  for (i=0; i<20; ++i) {p[i]=i; }
  for (i=0; i<20; ++i) { if (p[i] != i) should_never_happen(); }

Do you think that the proposed fix is ok ?



================
Comment at: lib/Analysis/ScopedNoAliasAA.cpp:454
+  DEBUG(dbgs() << "SNA: B does not derive from the compatible set!\n");
+
+  // Note: This can be removed when legacy-pass-manager support is removed;
----------------
We need an extra check here to see if APtr is directly depending on BPtr.  Something like following code should do the trick:

  {
    // Check if A depends directly on B
    SmallVector<Value *, 8> AObjs;
    GetUnderlyingObjects(const_cast<Value*>(APtr), AObjs, DL, nullptr, 0, nullptr);
    DEBUG(dbgs() << "SNA: underlying objects:\n");
  #ifndef NDEBUG
    for (auto *A : AObjs)
      DEBUG(dbgs() << "\t" << *A << "\n");
    DEBUG(dbgs() << "\n"); 
  #endif
    if (CSB) {
      for (Value* Arg : CSB.args())
        if (llvm::is_contained(AObjs, Arg)) {
          DEBUG(dbgs() << "SNA : A depends directly on B:"; Arg->dump());

          return false;
        }
    } else if (llvm::is_contained(AObjs, BPtr)) {
      DEBUG(dbgs() << "SNA : A depends directly on B:"; BPtr->dump());
      return false;
    }
  }


https://reviews.llvm.org/D9401





More information about the llvm-commits mailing list