Bug 38012 - vectorizer ignores 'restrict'
Summary: vectorizer ignores 'restrict'
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.2
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: alias, missed-optimization
Depends on:
Reported: 2008-11-04 16:04 UTC by David Monniaux
Modified: 2009-06-25 11:19 UTC (History)
1 user (show)

See Also:
Host: i486-linux-gnu
Target: i486-linux-gnu
Build: i486-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:

source code where va and vb are thought to be aliased (16.72 KB, text/plain)
2008-11-04 16:06 UTC, David Monniaux

Note You need to log in before you can comment on or make changes to this bug.
Description David Monniaux 2008-11-04 16:04:55 UTC
The vectorizer ignores the 'restrict' keyword regarding two pointer destinations, and emits a run-time aliasing text.
Comment 1 David Monniaux 2008-11-04 16:06:32 UTC
Created attachment 16623 [details]
source code where va and vb are thought to be aliased

The compiler should heed that va and vb cannot point to aliased locations.
Comment 2 Richard Biener 2008-11-04 16:10:20 UTC
restrict support is only roughly implemented.
Comment 3 Richard Biener 2009-06-25 11:19:50 UTC
  double* __restrict__ va;
  const double* __restrict__ vb;
  for(unsigned i=0; i<a.size(); i++) {
    va = &a[i];
    vb = &b[i];
    (*va) = (*vb) *coef;

this only says that a[i] and b[i] do not alias in one loop iteration, it doesn't
cover cross-iteration dependencies that the vectorizer needs.

  double* __restrict__ va = a;
  const double* __restrict__ vb = b;
  for(unsigned i=0; i<a.size(); i++) {
    va[i] = vb[i] *coef;

will work.