Bug 101450

Summary: GCC doesn't vectorize loop due to evolution of base is not affine.
Product: gcc Reporter: Hongtao.liu <crazylht>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 12.0   
Target Milestone: ---   
Host: x86_64-pc-linux-gnu Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2021-07-14 00:00:00
Bug Depends on:    
Bug Blocks: 53947    

Description Hongtao.liu 2021-07-14 12:08:25 UTC
the testcase is extracted from coremark

cat test.c

void
matrix_add_const(unsigned int N, short *A, short val)
{
  unsigned int i, j;
  for (i = 0; i < N; i++)
    {
      for (j = 0; j < N; j++)
        {
	  A[i * N + j] += val;
        }
    }
}

gcc failed to vectorize it since there could be wrap for i*N + j, but we can do multi-versioning for it?

llvm seems does that.

https://godbolt.org/z/Er44ffTE3
Comment 1 Richard Biener 2021-07-14 12:48:54 UTC
Yes, as I said in some other PRs the SCEV framework would need to be extended to track 'assumptions' under which its result would be valid, much like niter analysis does.  Currently it simply gives up here.  Of course 'assumptions'
would need support from quite some mid-stream infrastructure and some way
to carry it since currently a SCEV is a tree expression.

Thus it's quite some work to do this.

The mid-stream users is mostly data dependence analysis.

There's effective duplicates of this bug.