[llvm-dev] A bug in DependenceAnalysis?

Stanislav Manilov via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 21 08:56:09 PDT 2017

Hello llvm-dev,

I'm running a pass that uses the result of
llvm::DependenceAnalysisWrapperPass to compute the dependencies between all
instructions of a loop. I have the following two examples of code I wish to

example A:

void move_one(int *A, unsigned n) {
  for (unsigned i = 0; i < n-1; ++i) {
    A[i] = A[i + 1];
and example B:
void move_one_alt(int *A, unsigned n) {
  int *B = A + 1;
  for (unsigned i = 0; i < n-1; ++i) {
    A[i] = B[i];

I would expect that I get the same result for both A and B, namely a loop
carried anti (WAR) dependence from the generated load instruction to the
generated store instruction. This should be the case, because on iteration
i+1 the loop is writing to the element that has been read in the previous
iteration - iteration i.

However, in example A I get a loop carried flow (RAW) dependence from the
store instruction to the load instruction, while in example B I don't get
any dependence at all.

Am I missing something, or is the result wrong?

 - Stan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170621/9cfe9a45/attachment.html>

More information about the llvm-dev mailing list