[PATCH] D70634: Ignore Unknown dependencies using vectorize.ivdep metadata

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 16:04:14 PST 2019


Meinersbur added a comment.

In D70634#1781787 <https://reviews.llvm.org/D70634#1781787>, @YashasAndaluri wrote:

> In D70634#1758952 <https://reviews.llvm.org/D70634#1758952>, @Meinersbur wrote:
>
> > [serious] We did not come to a conclusion during the discussion <https://lists.llvm.org/pipermail/llvm-dev/2019-August/134592.html> about the semantics ivdep being implementation-dependent.
>
>
> I was under the impression that Unknown dependencies were ambiguous to the vectorizer and so would be along the lines of the Cray semantics. Please suggest what would be a good approach for this.


Cray's semantics are dangerous in that it may unpredictably miscompile depending on which compiler you are using. Just being slower would have been fine. The issue is that there might not be a good approach and I am not convinced that approximated compatibility to Cray is a good-enough reason to introduce unpredictable miscompilation. However, just parsing #pragma ivdep but ignoring it might be fine.

Why may it miscompile unpredictably? Consider:

  #pragma ivdep
  for (int i = 0; i < n; i+=1)
    sum[i/n] += A[i];

Since `0 <= i < n`, `i/n` will always evaluate to 0. But does the compiler known? If it does, it might recognize the reduction in

  double tmp = sum[0];
  for (int i = 0; i < n; i+=1)
    tmp += A[i];
  sum[0] = tmp;

and vectorize it correctly. However, if it does not, ivdep allows it to ignore the loop-carried dependency and write arbitrary values to `sum[0]` (for instance just the last value `sum[0] = A[n-1]`), i.e. miscompile the reduction.

We cannot assume that LLVM's capability to recognize dependencies and reductions are stricly superior over Cray's, hence miscompile programs that Cray's compiler did not. Even worse, the user cannot deduce whether their code will be compiled correctly or not.


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

https://reviews.llvm.org/D70634





More information about the llvm-commits mailing list