-qalias

Category

Optimization and tuning

Purpose

Indicates whether a program contains certain categories of aliasing or does not conform to Fortran standard aliasing rules. The compiler limits the scope of some optimizations when there is a possibility that different names are aliases for the same storage location.

Syntax

Read syntax diagramSkip visual syntax diagram
                  .-:--------------.   
                  | .-std--------. |   
                  | +-pteovrlp---+ |   
                  | +-nointptr---+ |   
                  V +-aryovrlp---+ |   
>>- -q--alias--=----+-noaryovrlp-+-+---------------------------><
                    +-intptr-----+     
                    +-nopteovrlp-+     
                    '-nostd------'     

@PROCESS:

@PROCESS  ALIAS( {ARGUMENT_LIST} )

Defaults

-qalias=aryovrlp:nointptr:pteovrlp:std

Parameters

aryovrlp | noaryovrlp
Indicates whether the compilation units contain any array assignments between storage-associated arrays. If not, specify noaryovrlp to improve performance.
intptr | nointptr
Indicates whether the compilation units contain any integer POINTER statements. If so, specify intptr.
pteovrlp | nopteovrlp
Indicates whether any pointee variables may be used to refer to any data objects that are not pointee variables, or whether two pointee variables may be used to refer to the same storage location. If not, specify nopteovrlp.
std | nostd
Indicates whether the compilation units contain any nonstandard aliasing (which is explained below). If so, specify nostd.

Usage

An alias exists when an item in storage can be referred to by more than one name. The Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 standards allow some types of aliasing and disallow some others. The sophisticated optimizations that the XL Fortran compiler performs increase the likelihood of undesirable results when nonstandard aliasing is present, as in the following situations:
  • The same data object is passed as an actual argument two or more times in the same subprogram reference. The aliasing is not valid if either of the actual arguments becomes defined, undefined, or redefined.
  • A subprogram reference associates a dummy argument with an object that is accessible inside the referenced subprogram. The aliasing is not valid if any part of the object associated with the dummy argument becomes defined, undefined, or redefined other than through a reference to the dummy argument.
  • A dummy argument becomes defined, undefined, or redefined inside a called subprogram in some other way than through the dummy argument.
  • A subscript to an array within a common block exceeds that array's bounds.

The -qipa option does not remove the need for -qalias.

Restrictions

Because this option inhibits some optimizations of some variables, using it can lower performance.

Programs that contain nonstandard or integer POINTER aliasing may produce incorrect results if you do not compile them with the correct -qalias settings. When you use the xlf, xlf_r, or xlf_r7 invocation command to compile the .f, .F, .f77, or .F77 files, or when you use the f77 or fort77 invocation command, the compiler assumes that integer POINTERs might be present (-qalias=aryovrlp:pteovrlp:std:intptr). All the other invocation commands assume that a program contains only standard aliasing (-qalias=aryovrlp:pteovrlp:std:nointptr).

Examples

If the following subroutine is compiled with -qalias=nopteovrlp, the compiler may be able to generate more efficient code. You can compile this subroutine with -qalias=nopteovrlp, because the integer pointers, ptr1 and ptr2, point at dynamically allocated memory only.

  subroutine sub(arg)
      real arg
      pointer(ptr1, pte1)
      pointer(ptr2, pte2)
      real pte1, pte2

      ptr1 = malloc(%val(4))
      ptr2 = malloc(%val(4))
      pte1 = arg*arg
      pte2 = int(sqrt(arg))
      arg = pte1 + pte2
      call free(%val(ptr1))
      call free(%val(ptr2))
  end subroutine 

If most array assignments in a compilation unit involve arrays that do not overlap but a few assignments do involve storage-associated arrays, you can code the overlapping assignments with an extra step so that the NOARYOVRLP suboption is still safe to use.

@PROCESS ALIAS(NOARYOVRLP)
! The assertion that no array assignments involve overlapping
! arrays allows the assignment to be done without creating a
! temporary array.
      program test
        real(8) a(100)
        integer :: j=1, k=50, m=51, n=100

        a(1:50) = 0.0d0
        a(51:100) = 1.0d0

        ! Timing loop to achieve accurate timing results
        do i = 1, 1000000
           a(j:k) = a(m:n)    ! Here is the array assignment
        end do

        print *, a
      end program
! We cannot assert that this unit is free
! of array-assignment aliasing because of the assignments below.
      subroutine sub1
      integer a(10), b(10)
      equivalence (a, b(3))
      a = b          ! a and b overlap.
      a = a(10:1:-1) ! The elements of a are reversed.
      end subroutine

! When the overlapping assignment is recoded to explicitly use a
! temporary array, the array-assignment aliasing is removed.
! Although ALIAS(NOARYOVRLP) does not speed up this assignment,
! subsequent assignments of non-overlapping arrays in this unit
! are optimized.
@PROCESS ALIAS(NOARYOVRLP)
      subroutine sub2
      integer a(10), b(10), t(10)
      equivalence (a, b(3))
      t = b; a = t
      t = a(10:1:-1); a = t
      end subroutine

When SUB1 is called, an alias exists between J and K. J and K refer to the same item in storage. In Fortran, this aliasing is not permitted if J or K are updated, and, if it is left undetected, it can have unpredictable results.

       CALL SUB1(I,I)
       …
       SUBROUTINE SUB1(J,K)
In the following example, the program might store 5 instead of 6 into J unless -qalias=nostd indicates that an alias might exist.
       INTEGER BIG(1000)
       INTEGER SMALL(10)
       COMMON // BIG
       EQUIVALENCE(BIG,SMALL)
       …
       BIG(500) = 5
       SMALL (I) = 6   ! Where I has the value 500
       J = BIG(500)

Related information