https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112892
Bug ID: 112892
Summary: MAX<VEC_PERM<a,a,c>, VEC_PERM<b,b,c>> could be just
VEC_PERM<MAX<a,b>,...,c>
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
static inline int MAX(int a, int b)
{
if (a < b) return b;
return a;
}
void f(int *a, int n)
{
n = 128;
int i;
for(i = n-1; i >= 1; i--)
{
a[i] = MAX(a[i], a[i-1]);
}
}
```
Currently we vectorize to:
```
vect__4.9_43 = MEM <vector(4) int> [(int *)vectp_a.7_41];
vect__4.10_44 = VEC_PERM_EXPR <vect__4.9_43, vect__4.9_43, { 3, 2, 1, 0 }>;
vect__7.13_48 = MEM <vector(4) int> [(int *)vectp_a.7_41 + -4B];
vect__7.14_49 = VEC_PERM_EXPR <vect__7.13_48, vect__7.13_48, { 3, 2, 1, 0 }>;
vect__12.15_50 = MAX_EXPR <vect__4.10_44, vect__7.14_49>;
vect__12.18_54 = VEC_PERM_EXPR <vect__12.15_50, vect__12.15_50, { 3, 2, 1, 0
}>;
MEM <vector(4) int> [(int *)vectp_a.7_41] = vect__12.18_54;
```
But the VEC_PERMs here can be removed ...
as we are generating the opposite vector and such.