https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92980
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2019-12-18
Ever confirmed|0 |1
Severity|normal |enhancement
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think the problem is we are folding the right side of the array (with the
conversion to size_t) too early.
That is:
src1[j-1]
Is being folded too early to have (j-1)*4
Fixing this up in match.pd is wrong.
This gets us the best code without any patch to match.pd:
int foo(unsigned int *__restrict src1, int i, int k, int n)
{
int j = k + n;
int sum = src1[j];
int jj = j-1;
sum += src1[jj];
if (i <= k)
{
j+=2;
int ii = j-3;
sum += src1[ii];
}
return sum + j;
}
See how j-1 and j-3 are not folded early and that fixes the issue.