[llvm-dev] Field sensitive alias analysis?

Vaivaswatha Nagaraj via llvm-dev llvm-dev at lists.llvm.org
Fri Dec 4 00:06:53 PST 2015


Hi,

I'm trying to optimize a simple C code and came across a situation where
invariant code is not being moved out:

On an -O3 compilation, I noticed that the "load" for the loop bounds (which
remain invariant throughout) happens on each iteration of both the loops,
even though it is not modified anywhere in the function "bigLoop". It seems
that alias analysis is not able to say that the writes to one field in the
structure does not impact the other field, leading to LICM being
ineffective.

Do any of the alias analyses currently have some kind of field sensitivity
that can help in this case?

------------------------- test case ------------------------------------
#include <stdlib.h>
#include <stdio.h>

#define SIZE 100

struct AS {
  int a[SIZE+4];
  int size;
} A;

void bigLoop(void)
{
  unsigned i, j;

  for (i = 0; i < A.size; i++) {
    A.a[i+2] +=  A.a[i];
  }
  for (i = 0; i < A.size; i++) {
    A.a[i+2] *=  A.a[i];
  }
}

int main()
{
  A.size = random()%SIZE;
  for (unsigned i = 0; i < A.size; i++) {
    A.a[i] = random()%23;
  }
  bigLoop();
  return 0;
}

Thanks,

  - Vaivaswatha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151204/330e6071/attachment.html>


More information about the llvm-dev mailing list