https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112457
Bug ID: 112457 Summary: Possible better vectorization of different reduction min/max reduction Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: juzhe.zhong at rivai dot ai Target Milestone: --- Hi, Richard. GCC-14 almost has all features of RVV. I am planning to participate on improving GCC loop vectorizer in GCC-15. Fix FAILs of TSVC is one of my plan. Currently we can vectorize this following case: int idx = 0; int max = 0; void foo (int n, int * __restrict a){ for (int i = 0; i < n; ++i) { max = max < a[i] ? a[i] : max; } } However, if we change this case it failed: void foo2 (int n, int * __restrict a){ for (int i = 0; i < n; ++i) { if (max < a[i]) { max = a[i]; } else max = max; } } Now, I notice another interesting and possible vectorization enhancement which inspired by this patch of LLVM: https://reviews.llvm.org/D143465 And more advance case is which is case from LLVM patch: which is vectorization reduction with index: void foo3 (int n, int * __restrict a){ for (int i = 0; i < n; ++i) { if (max < a[i]) { idx = i; max = a[i]; } } } I wonder it is a valuable optimization ? If yes, it would be one of my TODO list. Thanks.