Next: 8.1.6 Algebraic Simplifications Up: 8.1 Optimizations Previous: 8.1.4 Loop Optimizations Contents Index

##
8.1.5 Loop Reversing

This optimization is done to reduce the overhead of checking loop boundaries for every iteration. Some simple loops can be reversed and implemented using a ``decrement and jump if not zero'' instruction. SDCC checks for the following criterion to determine if a loop is reversible (note: more sophisticated compilers use data-dependency analysis to make this determination, SDCC uses a more simple minded analysis).

- The 'for' loop is of the form
  `for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym> += 1])`
  `<for body>`
- The <for body> does not contain ``continue'' or 'break''.
- All goto's are contained within the loop.
- No function calls within the loop.
- The loop control variable <sym> is not assigned any value within the loop
- The loop control variable does NOT participate in any arithmetic operation within the loop.
- There are NO switch statements in the loop.