This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
About loop unrolling and optimize for size
- From: "sarah at hederstierna dot com" <fredrik at hederstierna dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 13 Aug 2015 16:26:53 +0000
- Subject: About loop unrolling and optimize for size
- Authentication-results: sourceware.org; auth=none
Hi
I'm using an ARM thumb cross compiler for embedded systems and always do optimize for small size with -Os.
Though I've experimented with optimization flags, and loop unrolling.
Normally loop unrolling is always bad for size, code is duplicated and size increases.
Though I discovered that in some special cases where the number of iteration is very small, eg a loop of 2-3 times,
in this case an unrolling could make code size smaller - eg. losen up registers used for index in loops etc.
Example when I use the flag "-fpeel-loops" together with -Os I will 99% of the cases get smaller code size for ARM thumb target.
Some my question is how unrolling works with -Os, is it always totally disabled,
or are there some cases when it could be tested, eg. with small number iterations, so loop can be eliminated?
Could eg. "-fpeel-loops" be enabled by default for -Os perhaps? Now its only enabled for -O2 and above I think.
Thanks and Best Regards
Fredrik