Bug 43425 - gcc should vectorize this loop by substitution
Summary: gcc should vectorize this loop by substitution
Status: RESOLVED DUPLICATE of bug 35229
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2010-03-18 18:14 UTC by Changpeng Fang
Modified: 2012-07-19 11:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-03-18 18:31:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Changpeng Fang 2010-03-18 18:14:16 UTC
chfang@pathscale:~/gcc$ cat foo.c
int a[100], b[100];

void foo(int n, int mid)
{
  int i, t = 0;
  for(i=0; i<n; i++)
    {
      a[i] = b[i] + t; 
      t = b[i];
    }
}
chfang@pathscale:~/gcc$ gcc -O3 -ftree-vectorizer-verbose=7 -c foo.c

foo.c:6: note: not vectorized: unsupported use in stmt.
foo.c:3: note: vectorized 0 loops in function.

scalar expansion of t into array to carry the values accross iteration.
Comment 1 Andrew Pinski 2010-03-18 18:31:30 UTC
Basically undoing predictive commoning (which we switched the order for 4.5 to fix a different issue).  Confirmed.
Comment 2 Ira Rosen 2010-03-28 08:59:32 UTC
I think PR 35229 covers this issue.
Comment 3 Changpeng Fang 2010-05-07 21:33:21 UTC
I just found that the test case in the same as (similar to) bug 35229.
The subject of this bug is wrong. Scalar expansion is not appropriate
for this case.

Actually the loop can be transform to:

void foo(int n)
{
  int i;
  a[0] = b[0]; /* + t if t live before this point */
  for(i=1; i<n; i++)
    {
      a[i] = b[i] + b[i-1]; 
    }
  /* t = b[n-1]; is t live after this point */
}

The this loop can be vectorized.

In open64, this optimization is called forward (backward) substitution, i.e. substitute t with b[i-1].

I am not clear whether bug 35229 addresses the same issue. Maybe we should close
one of them.
Comment 4 Richard Biener 2012-07-13 08:38:21 UTC
Link to vectorizer missed-optimization meta-bug.
Comment 5 Richard Biener 2012-07-19 11:28:19 UTC
Duplicate of 35229.

*** This bug has been marked as a duplicate of bug 35229 ***