https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120001
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Vincenzo Romano from comment #6) > MAybe I have not been clear. > In cases with -O2 and -O2 the infinite loop is over 2 amoor identical > instruction. > Maybe I don't know RISC-V architecture that well, but it looks like a bug to > me: one amoor should suffice, just like with -Os. Again GCC unrolled the loop. That is: l1: { amoor.d.aqrl a4,a5,0(a0) goto l1; } Into: l1: { amoor.d.aqrl a4,a5,0(a0) // goto l2; //l2: amoor.d.aqrl a4,a5,0(a0) goto l1 } Copied the inner block one time for better alignment/placement in this case. It does not change the behavior of the function since it is an infinite loop. Note this behavior shows up on aarch64 too (with -march=armv8.1-a). it is not riscv specific. It is done because the size of the basic block of the loop is small and copying it will be decent for the alignment.