SPRUI04F july 2015 – april 2023
When prologs and epilogs are collapsed, instructions might be speculatively executed, thereby causing loads to addresses beyond either end of the range explicitly read within the loop. By default, the compiler cannot speculate loads because this could cause an illegal memory location to be read. Sometimes, the compiler can predicate these loads to prevent over execution. However, this can increase register pressure and might decrease the total amount of collapsing which can be performed.
When the --speculate_loads=n option is used, the speculative threshold is increased from the default of 0 to n. When the threshold is n, the compiler can allow a load to be speculatively executed as the memory location it reads will be no more than n bytes before or after some location explicitly read within the loop. If the n is omitted, the compiler assumes the speculative threshold is unlimited. To specify this in Code Composer Studio, select the Speculate Threshold check box and leave the text box blank in the Build Options dialog box on the Compiler tab, Advanced category.
Collapsing of the prolog and epilog can usually reduce the minimum safe trip count. If the minimum known trip count is less than the minimum safe trip count, a redundant loop is required. Otherwise, pipelining must be suppressed. Both these values can be found in the comment block preceding a software pipelined loop.
;*Known Minimum Trip Count: 1
....
;*Minimum safe trip count: 7
If the minimum safe trip count is greater than the minimum known trip count, use of --speculate_loads is highly recommended, not only for code size, but for performance.
When using --speculate_loads, you must ensure that potentially speculated loads will not cause illegal reads. This can be done by padding the data sections and/or stack, as needed, by the required memory pad in both directions. The required memory pad for a given software-pipelined loop is also provided in the comment block for that loop.
;*Minimum required memory pad: 8 bytes