[llvm-bugs] [Bug 27955] New: Miscompilation of program using 'restrict' due to overaggressive vectorization

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 31 14:59:01 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27955

            Bug ID: 27955
           Summary: Miscompilation of program using 'restrict' due to
                    overaggressive vectorization
           Product: new-bugs
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: zwarich at apple.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Using Clang r271331 / LLVM r271325, the following program has different results
when compiled with -O0 and -O3. With -O0, the result is

0
1
3
6
10
15
21
28
36

With -O3, the result is

0
1
3
5
7
9
11
13
15

The problem is that the use of 'restrict' is converted into a 'noalias'
parameter that is then turned into 'alias.scope' metadata upon inlining. While
the original use of 'restrict' was just an assertion about the specific
arguments to 'add', the loop vectorizer assumes that the 'alias.scope' metadata
implies that there are additionally no interiteration dependencies, which is
false.

---
#include <stddef.h>
#include <stdio.h>

static void add(int* restrict p, int* q) {
  *p += *q;
}

__attribute__((noinline)) void f(int* a, int* b, size_t size) {
  for (size_t i = 0; i < size; i++) {
    add(&a[i], &b[i]);
  }
}

int main() {
  const size_t kArraySize = 9;
  int a[kArraySize];

  for (size_t i = 0; i < kArraySize; i++) {
    a[i] = i;
  }

  f(a + 1, a, kArraySize - 1);

  for (size_t i = 0; i < kArraySize; i++) {
    printf("%d\n", a[i]);
  }
}
---

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160531/53b5b2dd/attachment-0001.html>


More information about the llvm-bugs mailing list