In fact, modern compilers can optimize code. True, they do it not in the best way, but often this is enough. One of the standard methods is to unroll cycles into a linear code, because it is more convenient for the processor to execute a code without branching. Even during optimization, it is necessary to take into account the peculiarities of the processor architecture, in particular, how they work with RAM. And it turns out that by optimizing the code for one of the processors, you can get a completely non-optimal code for others. Well, and besides, there are different optimization criteria. There are two main ones: by the speed of code execution and by the code size. So, the compilers introduce keys for the exact task for what and how you want to optimize.
So, in your case, you should try to test different versions of the program and conclude that it is better, independently. Moreover, it is desirable to check with different compilation modes.