-Ol: Try to Keep Loop Induction Variables in Registers

Group

OPTIMIZATIONS

Scope

Function

Syntax
  -Ol<number>
  
  
Arguments

<number>: number of registers to be used for induction variables

Default

None

Defines

None

Pragmas

None

Description

This option limits the number of loop induction variables the Compiler keeps in registers. Specify any number down to zero (no loop induction variables). The compiler reads and writes loop induction variables within the loop (for example, loop counter), and attempts to keep the variables in registers to reduce execution time and code size. The Compiler takes the optimal number (code density) when this option is not specified. Specifying a high number of loop induction variables may increase code size, particularly for spill and merge code.

Note: Disable this option (with -Ol0) if problems occur while debugging. This optimization may increase code complexity when using High-Level Languages, making debugging more difficult.

Listing: With the -Ol0 Option (No Optimization, Pseudo Code) and Listing: Without Option (Optimized, Pseudo Assembler) use the example in Listing: Example (Abstract Code).

Listing: Example (Abstract Code)


void main(char *s) {
  do {

    *s = 0;

  } while (*++s);

}

The following listing shows pseudo disassembly with the -Ol0 option:

Listing: With the -Ol0 Option (No Optimization, Pseudo Code)


loop:
  LD  s, Reg0

  ST  #0, [Reg0]

  INC Reg0

  ST  Reg0, s

  CMP [Reg0],#0

  BNE loop

The following listing shows pseudo disassembly without the -Ol option (i.e., optimized). Loads and stores from or to variable s disappear.

Listing: Without Option (Optimized, Pseudo Assembler)


loop:
  ST  #0, s

  INC s

  CMP s,#0

  BNE loop
Example
  -Ol1