C++ Compiler Optimizations

From Appmethod Topics
Jump to: navigation, search

Go Up to C++ Compiler


Project > Options > C++ Compiler > Optimizations

Use this dialog box to set C++ compiler optimization options.

Options Description

Target, Apply, Save

See Target Options.

Common items

See Common Items on Project Options Pages.


Optimizations Options Description Compiler support
bcc32 bcc32c bcc64 bccosx bcciosarm bcciosarm64 bccaarm

Disable all optimizations

Disables all optimization settings, including ones that you may have specifically set and those that would normally be performed as part of the speed/size trade-off. Because this disables code compaction (tail merging) and cross-jump optimizations, using this option can keep the debugger from jumping around or returning from a function without warning, which makes stepping through code easier to follow. Default = True

YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png

Enable selected optimizations

Enables only the optimizations that you select from the secondary list of optimizations. Default = False

Dead store elimination

Removes superfluous stores. Click the down-arrow to select from the possible values (True, False). Default = False

Eliminate duplicate expressions within basic blocks and functions

Instructs the compiler to eliminate common subexpressions within groups of statements unbroken by jumps (basic blocks) and functions. This option globally eliminates duplicate expressions within the target scope and stores the calculated value of those expressions once (instead of recalculating the expression). Use this option if you prefer to reuse expressions rather than create explicit stack locations for them. Default = False

Enable loop induction variable and strength reduction

Instructs the compiler to create induction variables and perform strength reduction, which optimizes for loops speed. Use this option when you are compiling for speed and your code contains loops.

The optimizer uses induction to create new variables (induction variables) from expressions used in loops. The optimizer assures that the operations performed on these new variables are computationally less expensive (reduced in strength) than those used by the original variables.

Optimizations are common if you use array indexing inside loops because a multiplication operation is required to calculate the position in the array that is indicated by the index. For example, the optimizer creates an induction variable out of the operation v[i] in the following code because the v[i] operation requires multiplication. This optimization also eliminates the need to preserve the value of i:

int v[10];
void f(int x, int y, int z)
{ int i;
  for (i = 0; i < 10; i++)
    v[i] = x * y * z;
}

With induction variables set, the code changes:

int v[10];
void f(int x, int y, int z)
{ int i, *p;
  for (p = v; p < &v[9]; p++)
  *p = x * y * z;
}

Default = False

Enable Pentium instruction scheduling

Generates Pentium instructions. While this option increases the speed at which the application runs on Pentium machines, expect the program to be a bit larger than when compiled with the 80386 or i486 options. Also, Pentium-compiled code sustains a performance hit on non-Pentium systems. Default = False

Expand common intrinsic functions

Instructs the compiler to generate the code for common memory functions like strcpy() within your function's scope. This eliminates the need for a function call. The resulting code executes faster, but it is larger. The following functions are inlined with this option:

alloca, fabs, memchr, memcmp, memcpy, memset, rotl, rotr, stpcpy, strcat, strchr, strcmp, strcpy, strlen, strncat, strncmp, strncpy, strnset, strrchr.

You can control the inlining of these functions with the pragma intrinsic. For example,

#pragma intrinsic strcpy

causes the compiler to generate inline code for all subsequent calls to strcpy in your function, and

#pragma intrinsic -strcpy

prevents the compiler from inlining strcpy. Using these pragmas in a file overrides any compiler option settings.
Default = False

Optimize jumps

Instructs the compiler to reduce the code size by eliminating redundant jumps and reorganizing loops and switch statements. When this option is set, the sequences of stepping in the debugger can be confusing because of the reordering and elimination of instructions. If you are debugging at the assembly level, you might want to disable this option. Default = False

Use register variables

Instructs the compiler to automatically assign register variables if possible, even when you do not specify a register variable by using the register keyword. Default = False

YesC++11Feature.png
YesC++11Feature.png

Generate fastest possible code

This switch sets an aggregate of optimization options that tells the compiler to optimize your code for speed. Either this option or Generate smallest possible code must be True, and they are mutually exclusive. Default = False

YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png

Generate smallest possible code

Sets an aggregate of optimization options that tells the compiler to optimize your code for size. For example, the compiler scans the generated code for duplicate sequences. When such sequences warrant, the optimizer replaces one sequence of code with a jump to the other and eliminates the first piece of code. This occurs most often with switch statements. The compiler optimizes for size by choosing the smallest code sequence possible. Either this option or Generate fastest possible code must be True, and they are mutually exclusive. Default = False

YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png
YesC++11Feature.png

See Also