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
Parallel Programming Guide for HP-UX Systems: K-Class and V-Class Servers > Chapter 4 Standard optimization features

Machine instruction level optimizations (+O0)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

At optimization level +O0, the compiler performs optimizations that span only a single source statement. This is the default. The +O0 machine instruction level optimizations include:

  • Constant folding

  • Partial evaluation of test conditions

  • Simple register assignment

  • Data alignment on natural boundaries

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. This is known as short-circuiting. The Fortran example below describes this:

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 (GRA)” 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.

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.

Data alignment on natural boundaries

The following Fortran example describes the alignment of data objects to their natural boundaries:

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 unused bytes after BOOL in order to correctly align A, and it must insert 4 unused 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. This is not to be confused with cache line boundary alignment.

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