Software Optimization Guide for AMD64 Processors

25112 Rev. 3.06 September 2005

2.2Using Arrays and Pointers

Optimization

Use array notation instead of pointer notation when working with arrays.

Application

This optimization applies to:

32-bit software

64-bit software

Rationale

C allows the use of either the array operator ([]) or pointers to access the elements of an array. However, the use of pointers in C makes work difficult for optimizers in C compilers. Without detailed and aggressive pointer analysis, the compiler has to assume that writes through a pointer can write to any location in memory, including storage allocated to other variables. (For example, *p and *q can refer to the same memory location, while x[0] and x[2] cannot.) Using pointers causes aliasing, where the same block of memory is accessible in more than one way. Using array notation makes the task of the optimizer easier by reducing possible aliasing.

10

C and C++ Source-Level Optimizations

Chapter 2

Page 26
Image 26
AMD 250 manual Using Arrays and Pointers