https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78180
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> --- By moving the array to be end of struct Rolling, GCC does the correct thing and optimizing out the load of idx out of the loop. That is: template <class C> class Rolling { uint32_t idx_; const uint32_t size_; C times_{}; ----- CUT----------- Basically: MEM[(value_type &)&r][_54] = _2; Is not treated as referencing the array field but rather referencing the whole struct so SRA thinks it cannot do anything with it.