[PATCH] D109821: [ScalarEvolution] Infer loop max trip count from array accesses

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 19 12:27:54 PDT 2021


xbolva00 added inline comments.


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7353
+      // Make sure only handle normal array.
+      auto *Ty = dyn_cast<ArrayType>(AllocateInst->getAllocatedType());
+      auto *ArrSize = dyn_cast<ConstantInt>(AllocateInst->getArraySize());
----------------
reames wrote:
> FYI, we can do better here by using getAllocationSizeInBits, but please *don't* change this in the current patch.  We're converging towards a LGTM, and minimal change is good.  It would make a good follow up though.
getAllocationSizeInBits will not probably catch this case, or?

```
int foo(int data[static 6]) { // define dso_local i32 @foo(i32* nocapture readonly align 4 dereferenceable(24) %0) 
  int p = 0;
  int i = 0;
  while (data[i++] != -1) // currently GCC does not unroll this loop 6x
     p += data[i];
  return p;
}

```

or when data is allocated using malloc/calloc/..


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

https://reviews.llvm.org/D109821



More information about the llvm-commits mailing list