<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68374>68374</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
__restrict on struct member has no effect (regression vs. GCC)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dsharlet
</td>
</tr>
</table>
<pre>
The following code demonstrates the issue:
```
const int N = 8;
struct A {
float * x;
};
struct B {
float * __restrict x;
};
void add1(const float * __restrict a, const float * __restrict b, float * __restrict c) {
for (int i = 0; i < N; i++) {
c[i] = a[i] + b[i];
}
}
void add2(A a, A b, A c) {
for (int i = 0; i < N; i++) {
c.x[i] = a.x[i] + b.x[i];
}
}
void add3(B a, B b, B c) {
for (int i = 0; i < N; i++) {
c.x[i] = a.x[i] + b.x[i];
}
}
```
When I compile this with clang trunk with -O2, I see:
- `add1` has a single vector add
- `add2` and `add3` are scalar code only.
When I compile this with gcc, I see:
- `add1` has a single vector add
- `add2` generates scalar code
- `add3` has a single vector add
As expected. The difference is `add3` in clang should generate vector code, like gcc, but it does not.
I reported this back a while back on LLVM bugzilla: https://bugs.llvm.org/show_bug.cgi?id=45863. At the time, Jeroen Dobbelaere was working on https://reviews.llvm.org/D69542 (reviewed by @hfinkel and @jdoerfert) which would fix this, but I can't tell if those changes landed, and the migration to github PRs has made it a little tricky to figure out what happened. I don't see any open PRs regarding `restrict` currently.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVc2O4zYMfhrlQozhyD9JDj4kE6SYYrstiqI9LmSJtrVRpECix5M-fSE5k5kUg20L7KGAIZsWSX38SJEiBN1bxIZVO1btF2KkwflGhUF4g7Ronbo0vw0InTPGTdr2IJ1CUHhyNpAXhAFoQNAhjMiKLcv3LH9d6_z6JFFGC9CW4DOwYg9rVuzeqwfyoyTYAltd_wN0xgkCxrfw8qa92n9sufvY8ssXj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