https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88315
Bug ID: 88315 Summary: SAD and DOT_PROD SLP reductions with initial value != 0 create wrong code Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- Index: gcc/testsuite/gcc.dg/vect/slp-reduc-sad.c =================================================================== --- gcc/testsuite/gcc.dg/vect/slp-reduc-sad.c (revision 266739) +++ gcc/testsuite/gcc.dg/vect/slp-reduc-sad.c (working copy) @@ -12,7 +12,7 @@ extern void abort (void); int __attribute__((noinline,noclone)) foo (uint8_t *pix1, uint8_t *pix2, int i_stride_pix2) { - int i_sum = 0; + int i_sum = 5; for( int y = 0; y < 16; y++ ) { i_sum += abs ( pix1[0] - pix2[0] ); @@ -52,7 +52,7 @@ main () __asm__ volatile (""); } - if (foo (X, Y, 16) != 32512) + if (foo (X, Y, 16) != 32512 + 5) abort (); return 0; FAILs at runtime. This is because number_of_copies = nunits * number_of_vectors / group_size; is zero as both SAD and DOT_PROD reduce to half the number of lanes and thus for example nunits == 4, number_of_vectors == 1 but group_size == 8. Looks like GCC 7, 8 and trunk are affected.