Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Fortran 90, Fortran 77, C, aC++: Exemplar Programming Guide > Chapter 3 Compiler optimizations

+O0 level optimizations

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

At optimization level +O0, the compiler performs the following optimizations that span no more than a single source statement:

  • Constant folding

  • Partial evaluation of test conditions

  • Simple register assignment

  • Data alignment on natural boundaries

The default optimization level is +O0.

Constant folding

Constant folding is the replacement of operations on constants with the result of the operation. For example, Y=5+7 is replaced with Y=12.

More advanced constant folding is performed at optimization level +O2. See the section “Advanced constant folding and propagation” for more information.

Partial evaluation of test conditions

Where possible, the compiler determines the truth value of a logical expression without evaluating all the operands (also known as short-circuiting). Consider the Fortran example below:

IF ((I .EQ. J) .OR. (I .EQ. K)) GOTO 100

If (I .EQ. J) is true, control immediately goes to 100; otherwise, (I .EQ. K) must be evaluated before control can go to 100 or the following statement.

Do not rely upon partial evaluation if you use function calls in the logical expression because:

  • There is no guarantee on the order of evaluation.

  • A procedure or function call can have side effects on variable values that may or may not be partially evaluated correctly.

Simple register assignment

The compiler may place frequently used variables in registers to avoid more costly accesses to memory.

A more advanced register assignment algorithm is used at optimization level +O2. See the section “Global register allocation” for more information.

Data alignment on natural boundaries

The compiler automatically aligns data objects to their natural boundaries in memory, providing more efficient access to data. This means that a data object's address is integrally divisible by the length of its data type; for example, REAL*8 objects have addresses integrally divisible by 8 bytes.

NOTE: Aliases can inhibit data alignment. Be especially careful when equivalencing arrays in Fortran.

You should declare scalar variables in order from longest to shortest data length to ensure the efficient layout of such aligned data in memory. This minimizes the amount of padding the compiler has to do to get the data onto its natural boundary.

Consider the following Fortran example:

C     CAUTION: POORLY ORDERED DATA FOLLOWS:
LOGICAL*2 BOOL
INTEGER*8 A, B
REAL*4 C
REAL*8 D

Here, the compiler must insert 6 blank bytes after BOOL in order to correctly align A, and it must insert 4 blank bytes after C to correctly align D.

The same data is more efficiently ordered as shown in the following example:

C     PROPERLY ORDERED DATA FOLLOWS:
INTEGER*8 A, B
REAL*8 D
REAL*4 C
LOGICAL*2 BOOL

Natural boundary alignment is performed on all data. Do not confuse It with cache line boundary alignment, which is performed as described in the section “Data alignment”. Also discussed in Chapter 2 are the align_cti directive and pragma, which facilitate CTIcache line boundary alignment.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.