OSDN Git Service

BasicAA: Recognize cyclic NoAlias phis
authorArnold Schwaighofer <arnolds@codeaurora.org>
Thu, 6 Sep 2012 14:41:53 +0000 (14:41 +0000)
committerArnold Schwaighofer <arnolds@codeaurora.org>
Thu, 6 Sep 2012 14:41:53 +0000 (14:41 +0000)
commit3d5f96ee1bf5189e324089976026ed09b6be9e58
tree73b3ef2aa83257f6a3a4080528a1c46cc78baca3
parent64eacd9136dc45e54dd2728117f71403701fd39c
BasicAA: Recognize cyclic NoAlias phis

Enhances basic alias analysis to recognize phis whose first incoming values are
NoAlias and whose other incoming values are just the phi node itself through
some amount of recursion.

Example: With this change basicaa reports that ptr_phi and ptr_phi2 do not alias
each other.

bb:
 ptr = ptr2 + 1

loop:
  ptr_phi = phi [bb, ptr], [loop, ptr_plus_one]
  ptr2_phi = phi [bb, ptr2], [loop, ptr2_plus_one]
  ...
  ptr_plus_one = gep ptr_phi, 1
  ptr2_plus_one = gep ptr2_phi, 1

This enables the elimination of one load in code like the following:

extern int foo;

int test_noalias(int *ptr, int num, int* coeff) {
  int *ptr2 = ptr;
  int result = (*ptr++) * (*coeff--);
  while (num--) {
    *ptr2++ = *ptr;
    result +=  (*coeff--) * (*ptr++);
  }
  *ptr = foo;
  return result;
}

Part 2/2 of fix for PR13564.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163319 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/BasicAliasAnalysis.cpp
test/Analysis/BasicAA/phi-speculation.ll [new file with mode: 0644]