https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95018
Bug ID: 95018 Summary: Excessive unrolling for Fortran library array handling Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: tkoenig at gcc dot gnu.org Target Milestone: --- Created attachment 48488 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48488&action=edit Generated assembly The code generated for in_pack_i4.c from libgfortran on POWER9 is huge and, presumably, slow; I assume that other code in the library is similarly affected. The problem manifests itself in the unrolling of the loops which do all the work: while (src) { /* Copy the data. */ *(dest++) = *src; /* Advance to the next element. */ src += stride0; count[0]++; /* Advance to the next source element. */ index_type n = 0; while (count[n] == extent[n]) { /* When we get to the end of a dimension, reset it and increment the next dimension. */ count[n] = 0; /* We could precalculate these products, but this is a less frequently used path so probably not worth it. */ src -= stride[n] * extent[n]; n++; if (n == dim) { src = NULL; break; } else { count[n]++; src += stride[n]; } } } return destptr; } One problem here is the while (count[n] == extent[n]) loop. This is an odometer algorithm to look for the next element to go to. Most of the times, the while is false, so it is definitely not good. x86_64 does not appear to be affected.