-Oc: Common Subexpression Elimination (CSE)

Group

OPTIMIZATIONS

Scope

Function

Syntax
  -Oc
  
  
Arguments

None

Default

None

Defines

None

Pragmas

None

Description

This option is disabled and present only for compatibility reasons for the HC(S)08.

Performs common subexpression elimination (CSE). The Compiler generates the code for common subexpressions and assignments only once and reuses the result. Depending on available registers, a common subexpression may produce more code due to multiple spills.

Note: When the CSE is switched on, variable changes by aliases may generate incorrect optimizations.
Example
  -Oc
  
  

In the following listing using the CSE option causes incorrect optimizations. This option is disabled for the HC(S)08.

Listing: Example of Using CSE and Producing Incorrect Results


void main(void) {
  int x; 

  int *p;

  x = 7;  /* here the value of x is set to 7 */

  p = &x;

  *p = 6;  /* here x is set to 6 by the alias *p */

  /* here x is assumed to be equal to 7 and

     Error is called */

  if(x != 6) Error();

}
Note: This error does not occur if you declare x as volatile.