[llvm-dev] valid BasicAA behavior?

Chawla, Pankaj via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 17 11:34:46 PDT 2020

My understanding is that alias analysis returns results in the function scope, not in loop scope.
Since both the phis access both global arrays, that should results in BasicAA conservatively returning MayAlias.

I debugged this a little bit and narrowed it down to the section of the code in BasicAAResult::aliasPHI() which has this comment-
      // Analyse the PHIs' inputs under the assumption that the PHIs are
      // NoAlias.
      // If the PHIs are May/MustAlias there must be (recursively) an input
      // operand from outside the PHIs' cycle that is MayAlias/MustAlias or
      // there must be an operation on the PHIs within the PHIs' value cycle
      // that causes a MayAlias.
      // Pretend the phis do not alias.

It seems to be analyzing corresponding phi operands assuming the PHIs to be ‘Noalias’ to begin with.
IMHO, this setup does not work correctly for loop header phis.

From: Hiroshi Yamauchi <yamauchi at google.com>
Sent: Tuesday, March 17, 2020 8:38 AM
To: Chawla, Pankaj <pankaj.chawla at intel.com>
Cc: llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] valid BasicAA behavior?

Perhaps BasicAA is telling that A and B don't alias during one particular iteration of the loop even though they are swapped?

1:                                                ; preds = %0, %35
  %2 = phi double* [ getelementptr inbounds ([1000 x double], [1000 x double]* @Ag, i64 0, i64 0), %0 ], [ %4, %35 ]
  %3 = phi i32 [ 0, %0 ], [ %36, %35 ]
  %4 = phi double* [ getelementptr inbounds ([1000 x double], [1000 x double]* @Bg, i64 0, i64 0), %0 ], [ %2, %35 ]
  br label %5


On Mon, Mar 16, 2020 at 10:28 PM Chawla, Pankaj via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
Hi all,

I have this test case-

#define N 1000
extern double Ag[N];
extern double Bg[N];

void consume(double *A, double *B);

void swap_deps() {
  double *A = Ag;
  double *B = Bg;

  for (int i = 0; i < 97; ++i) {
    for (int j = 0; j < N; ++j) {
      B[j] = A[j] + 1;

    double *tmp = A;
    A = B;
    B = tmp;

  consume(A, B);

BasicAA is returning ‘NoAlias’ when queried for phis created in the i-loop for A and B.
I was expecting it to return MayAlias since A and B are being swapped in the outer loop and so they access same locations in alternate iterations of the i-loop.

Is BasicAA returning the correct result in this case?

LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200317/a8aa6c63/attachment.html>

More information about the llvm-dev mailing list