https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121029
Bug ID: 121029
Summary: GCC does not vectorize conditional min/max reduction
Product: gcc
Version: 16.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
Blocks: 53947
Target Milestone: ---
Take:
```
#define N 32
unsigned int ub[N];
unsigned int uc[N];
unsigned int doesnot (unsigned int b, unsigned int c)
{
unsigned int umax = 0;
/* max. */
for (int i = 0; i < N; i++) {
int t = uc[i];
if (ub[i] < N/2 )
umax = umax > t ? umax : t;
}
return umax;
}
```
GCC does not know how to vectorize conditional min/max reductions. I didn't
find a bug report for this so I am filing one.
It could be vectorized like:
Loop:
t = uc[i];
t = ub[i] < N/2 ? t : umax;
umax = MAX<umax, t>;
endloop
MAX_reduction<umax>
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations