Bug 104917 - No runtime alias test required for dependent reductions
Summary: No runtime alias test required for dependent reductions
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: vectorizer 87561
  Show dependency treegraph
 
Reported: 2022-03-14 13:51 UTC by Richard Biener
Modified: 2022-03-15 09:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2022-03-14 13:51:52 UTC
The testcase from PR87561 shows a case where we have two in-memory reductions that are possibly dependent but the runtime alias check isn't needed since
we only possibly re-order the summations in the reduction.  Small C testcase:

void foo (double *x, double *y, double * __restrict a, double * __restrict b)
{
  for (int i = 0; i < 1024; ++i)
    {
      x[i] += a[i];
      y[i] += b[i];
    }
}

here x[] and y[] are dependent but we can vectorize this just fine with
-fassociative-math, eliding the runtime alias check.
Comment 1 Jakub Jelinek 2022-03-15 09:12:49 UTC
What if x = y + 1 or y = x + 1 ?
Comment 2 Richard Biener 2022-03-15 09:21:49 UTC
(In reply to Jakub Jelinek from comment #1)
> What if x = y + 1 or y = x + 1 ?

We then do

  (y+1)[i] += a[i];
  (y+1)[i+1] += a[i+1];
  y[i] += a[i];
  y[i+1] += a[i+1];

instead of

  (y+1)[i] += a[i];
  y[i] += a[i];
  (y+1)[i+1] += a[i+1];
  y[i+1] += a[i+1];

which should be OK if re-associating the adds to y[i+1] is OK.