-qstrict

Pragma equivalent

None.

Purpose

Ensures that optimizations that are done by default at the -O3 and higher optimization levels, and, optionally at -O2, do not alter the semantics of a program.

This option is intended for situations where the changes in program execution in optimized programs produce different results from unoptimized programs.

Syntax

Read syntax diagramSkip visual syntax diagram
>>- -q--+-nostrict------------------------------------+--------><
        '-strict--+---------------------------------+-'   
                  |    .- :-----------------------. |     
                  |    V                          | |     
                  '-=----+-all------------------+-+-'     
                         +-none-----------------+         
                         +-precision------------+         
                         +-noprecision----------+         
                         +-exceptions-----------+         
                         +-noexceptions---------+         
                         +-ieeefp---------------+         
                         +-noieeefp-------------+         
                         +-nans-----------------+         
                         +-nonans---------------+         
                         +-infinities-----------+         
                         +-noinfinities---------+         
                         +-subnormals-----------+         
                         +-nosubnormals---------+         
                         +-zerosigns------------+         
                         +-nozerosigns----------+         
                         +-operationprecision---+         
                         +-nooperationprecision-+         
                         +-vectorprecision------+         
                         +-novectorprecision----+         
                         +-order----------------+         
                         +-noorder--------------+         
                         +-association----------+         
                         +-noassociation--------+         
                         +-reductionorder-------+         
                         +-noreductionorder-----+         
                         +-guards---------------+         
                         +-noguards-------------+         
                         +-library--------------+         
                         '-nolibrary------------'         

Defaults

  • -qstrict or -qstrict=all is always in effect when the -qnoopt or -O0 optimization level is in effect
  • -qstrict or -qstrict=all is the default when the -O2 or -O optimization level is in effect
  • -qnostrict or -qstrict=none is the default when the -O3 or higher optimization level is in effect

Parameters

The -qstrict suboptions include the following:

all | none
all disables all semantics-changing transformations, including those controlled by the ieeefp, order, library, precision, and exceptions suboptions. none enables these transformations.
precision | noprecision
precision disables all transformations that are likely to affect floating-point precision, including those controlled by the subnormals, operationprecision, vectorprecision, association, reductionorder, and library suboptions. noprecision enables these transformations.
exceptions | noexceptions
exceptions disables all transformations likely to affect exceptions or be affected by them, including those controlled by the nans, infinities, subnormals, guards, and library suboptions. noexceptions enables these transformations.
ieeefp | noieeefp
ieeefp disables transformations that affect IEEE floating-point compliance, including those controlled by the nans, infinities, subnormals, zerosigns, vectorprecision, and operationprecision suboptions. noieeefp enables these transformations.
nans | nonans
nans disables transformations that may produce incorrect results in the presence of, or that may incorrectly produce IEEE floating-point NaN (not-a-number) values. nonans enables these transformations.
infinities | noinfinities
infinities disables transformations that may produce incorrect results in the presence of, or that may incorrectly produce floating-point infinities. noinfinities enables these transformations.
subnormals | nosubnormals
subnormals disables transformations that may produce incorrect results in the presence of, or that may incorrectly produce IEEE floating-point subnormals (formerly known as denorms). nosubnormals enables these transformations.
zerosigns | nozerosigns
zerosigns disables transformations that may affect or be affected by whether the sign of a floating-point zero is correct. nozerosigns enables these transformations.
operationprecision | nooperationprecision
operationprecision disables transformations that produce approximate results for individual floating-point operations. nooperationprecision enables these transformations.
vectorprecision | novectorprecision
vectorprecision disables vectorization in loops where it might produce different results in vectorized iterations than in nonvectorized residue iterations. vectorprecision ensures that every loop iteration of identical floating-point operations on identical data produces identical results.

novectorprecision enables vectorization even when different iterations might produce different results from the same inputs.

order | noorder
order disables all code reordering between multiple operations that may affect results or exceptions, including those controlled by the association, reductionorder, and guards suboptions. noorder enables code reordering.
association | noassociation
association disables reordering operations within an expression. noassociation enables reordering operations.
reductionorder | noreductionorder
reductionorder disables parallelizing floating-point reductions. noreductionorder enables parallelizing these reductions.
guards | noguards
Specifying -qstrict=guards has the following effects:
  • The compiler does not move operations past guards, which control whether the operations are executed. That is, the compiler does not move operations past guards of the if statements, out of loops, or past guards of function calls that might end the program or throw an exception.
  • When the compiler encounters if expressions that contain pointer wraparound checks that can be resolved at compile time, the compiler does not remove the checks or the enclosed operations. The pointer wraparound check compares two pointers that have the same base but have constant offsets applied to them.

Specifying -qstrict=noguards has the following effects:

  • The compiler moves operations past guards.
  • The compiler evaluates if expressions according to language standards, in which pointer wraparounds are undefined. The compiler removes the enclosed operations of the if statements when the evaluation results of the if expressions are false.
library | nolibrary
library disables transformations that affect floating-point library functions; for example, transformations that replace floating-point library functions with other library functions or with constants. nolibrary enables these transformations.

Usage

The all, precision, exceptions, ieeefp, and order suboptions and their negative forms are group suboptions that affect multiple, individual suboptions. For many situations, the group suboptions will give sufficient granular control over transformations. Group suboptions act as if either the positive or the no form of every suboption of the group is specified. Where necessary, individual suboptions within a group (like subnormals or operationprecision within the precision group) provide control of specific transformations within that group.

With -qnostrict or -qstrict=none in effect, the following optimizations are turned on:
  • Code that may cause an exception may be rearranged. The corresponding exception might happen at a different point in execution or might not occur at all. (The compiler still tries to minimize such situations.)
  • Floating-point operations may not preserve the sign of a zero value. (To make certain that this sign is preserved, you also need to specify -qfloat=rrm, -qfloat=nomaf, or -qfloat=strictnmaf.)
  • Floating-point expressions may be reassociated. For example, (2.0*3.1)*4.2 might become 2.0*(3.1*4.2) if that is faster, even though the result might not be identical.
  • The optimization functions enabled by -qfloat=rsqrt. You can turn off the optimization functions by using the -qstrict option or -qfloat=norsqrt. With lower-level or no optimization specified, these optimization functions are turned off by default.
Specifying various suboptions of -qstrict[=suboptions] or -qnostrict combinations sets the following suboptions:
  • -qstrict or -qstrict=all sets -qfloat=norsqrt:rngchk. -qnostrict or -qstrict=none sets -qfloat=rsqrt:norngchk.
  • -qstrict=infinities, -qstrict=operationprecision, or -qstrict=exceptions sets -qfloat=norsqrt.
  • -qstrict=noinfinities:nooperationprecision:noexceptions sets -qfloat=rsqrt.
  • -qstrict=nans, -qstrict=infinities, -qstrict=zerosigns, or -qstrict=exceptions sets -qfloat=rngchk. Specifying all of -qstrict=nonans:nozerosigns:noexceptions or -qstrict=noinfinities:nozerosigns:noexceptions, or any group suboptions that imply all of them, sets -qfloat=norngchk.
Note: For details about the relationship between -qstrict suboptions and their -qfloat counterparts, see -qfloat.

To override any of these settings, specify the appropriate -qfloat suboptions after the -qstrict option on the command line.

Predefined macros

None.

Examples

To compile myprogram.c so that the aggressive optimization of -O3 are turned off, and division by the result of a square root is replaced by multiplying by the reciprocal (-qfloat=rsqrt), enter:
xlc myprogram.c -O3 -qstrict -qfloat=rsqrt
To enable all transformations except those affecting precision, specify:
xlc myprogram.c -qstrict=none:precision
To disable all transformations except those involving NaNs and infinities, specify:
xlc myprogram.c -qstrict=all:nonans:noinfinities
In the following code example, the if expression contains a pointer wraparound check. If you compile the code with the -qstrict=guards option in effect, the compiler keeps the enclosed foo() function; otherwise, the compiler removes the enclosed foo() function.
void foo()
{
                // You can add some operations here.
}

int main()
{
  char *p = "a";
  int k = 100;
  if(p + k < p) // This if expression contains a pointer wraparound check.
  {
    foo();      // foo() is the enclosed operation of the if statement.
  }
  return 0;
}

Related information



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us