Refining C/C++ Code
3-42
3.4.3.2
Eliminating Redundant Loops
Sometimes the compiler cannot determine if the loop always executes more
than the minimum safe trip count. Therefore, the compiler will generate two
versions of the loop:
-
An unpipelined version that executes if the trip count is less than the mini-
mum safe trip count.
-
A software-pipelined version that executes if the trip count is equal to or
greater than the minimum safe trip count.
Obviously, the need for redundant loops will hurt both codesize and to a lesser
extent, performance.
To indicate to the compiler that you do not want two versions of the loop, you
can use the -ms0 or -ms1 option. The compiler will generate the software pipe-
lined version of the loop only if it can prove the minumum trip count will always
be equal or greater than the effective minimum trip count of the software pipe-
lined version of the loop. Otherwise, the non pipelined version will be gener-
ated. In order to help the compiler generate only the software pipelined version
of the loop, use the MUST_ITERATE pragma and/or the -pm option to help the
compiler determine the known minimum trip count.
Note:
Use of -ms0 or -ms1 may result in a performance degredation
Using -ms0 or -ms1 may cause the compiler not to software pipeline a loop.
This can cause the performance of the loop to suffer.
When safe, the –mh option may also be used to reduce the need for a redun-
dant loop. The compiler performs an optimization called prolog/epilog collaps-
ing to reduce code size of pipelined loops. In particular, this optimization in-
volves rolling the prolog and/or epilog (or parts thereof) back into the kernel.
This can result in a major code size reduction. This optimization can also re-
duce the minimum trip count needed to safely execute the software-pipelined
loop, thereby eliminating the need for redundant loops in many cases.
The user can increase the compiler’s ability to perform this optimization by us-
ing the -mh, or -mhn option whenever possible. See the
TMS320C6000 Opti-
mizing C/C++ Compiler User’s Guide for more information about options.