https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30609
--- Comment #5 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- The problem with the test case is that both sum and count are transformational functions, i.e. they reduce the rank. So, ideally this would be translated into real sum = 0.; int count = 0; for (i=0; i<n; i++) { if (a[i] > 0) { count ++; sum += a[i]; } } return sum / count; but the scalarizer does not do that (currently), and neither does the middle end. It would require loop fusion. So, it is probably not useful to do common subexpression elimination for rank>0 expressions if they are the arguments of transformational functions.