i960 Processor Compiler User's Guide
11-4
11
Constant Expression Evaluation (Constant Folding)
A constant expression contains only constant operands and simple
arithmetic operators. Instead of storing the numbers and operators for
computation when the program executes, the compiler evaluates the
constant expression and uses the result. Constant folding is another name
for this optimization.
The examples in Table 11-2 show the effects of constant expression
evaluation. The variables
d and e are affected by bit-shift operations but
are still subject to constant expression evaluation.
Table 11-2 Examples of Constant Expression Evaluation
Original Source Text Replacement
a = 1 + 2; a = 3;
b = 3 - 4; b = -1;
c = 5 * 6; c = 30;
d = (2 << 1) + 1; d = 5;
e = (12 >> 2) + 2; e = 5;
f = 1.2 + 3.8; f = 5.0;
g = 10.0 * 0.5; g = 5.0;
h = i + 2 + 5; h = i + 7;
Any of the following data types can be operands subject to constant
expression evaluation:
• integers
• floating-point numbers
• pointers