alias Optimization Option

Syntax: Default:
opt(alias, rule[, yes])
opt(alias, rule, no)
opt(alias, rule, no)

This option determines which aliasing assertions are applied during optimization. You select assertions by specifying one of the following values for rule:

Two or more expressions that can denote the same memory address are aliases of each other. Aliases can be produced by pointers, function calls, or aggregates in your code. Allowing tighter aliasing rules by using this option enables more aggressive optimization.

By default, VisualAge C++ follows the standard aliasing rules that apply when optimization is enabled.

You can specify this option more than once, and add a rule to the assertions currently in use each time. You can also explicitly include the argument yes to turn the rule on. To turn off a rule that is currently on, specify no. If you omit both yes and no, yes is assumed.

The aliasing rules are described in the following table:

rule description
addr Any class of variable for which an address has not been taken is disjoint from indirect access through pointers.
allp Never alias pointers. No two pointers can point directly to the same storage location. This setting implicitly sets opt(alias, typ).
ansi Never alias pointers to different types. ANSI rules differ slightly from the rules for type-based aliasing. Do not specify opt(alias, ansi) if your program casts a pointer to a different type, except for casts to or from the following types:
  • the declared type of the object
  • a qualified version of the declared type of the object
  • a type that is the signed or unsigned type corresponding to the declared type of the object
  • an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union)
  • a character type
typ Never alias pointers to different types.

The example below shows how aliasing rules can affect the output of a program:

/* This testcase behaves differently when opt(alias,ansi) is specified:   */
/*------------------------------------------------------------------------*/ 
/* This program verifes that the ansi option causes the compiler          */ 
/* to use type-based aliasing when optimizing.                            */ 
/*                                                                        */ 
/* It will not work if inlining is on.                                    */ 
/* -----------------------------------------------------------------------*/ 
#include <stdio.h> 

int integer; 
float *ptr; 

int value_of_integer (int value) 
{ 
printf(" value is %d", value); 
return value; 
} 

int alias_in_effect(float *ptr) 
{ 
integer = 1; 
*ptr = 0; /* wipe out integer */ 

/* 
* if ansi aliasing is in effect, then the compiler 
* should assume that "ptr" never points to "integer" 
* and can therefore pass the constant 1 to value_of_integer(). 
* if value is 0 --> ansi aliasing is not in effect 
*/ 
return value_of_integer(integer); 
} 

int main(void) 
{ 
if (alias_in_effect( (float *) & integer)) { 
printf(" ansialias is in effect. "); 
return 0; 
} else { 
printf(" ansialias is not in effect "); 
return 1; 
} 
}

 



Incremental C++ Build
C Compilation
Configuration Files


Set Build Options
Build
Optimize Your Application


Optimization Options
Optimization Options