Exceptions in Optimized Programs

In rare circumstances, an MCH3601 exception message may occur in programs compiled with optimization level 30 (*FULL) or 40. This topic explains one example in which this message occurs. The same program does not receive an MCH3601 exception message when compiled with optimization level 10 (*NONE) or 20 (*BASIC). Whether the message in this example occurs depends on how your ILE HLL compiler allocates storage for arrays. This example might never occur for your language.

When you ask for optimization level 30 (*FULL) or 40, ILE attempts to improve performance by calculating array index references outside of loops. When you refer to an array in a loop, you are often accessing every element in order. Performance can be improved by saving the last array element address from the previous loop iteration. To accomplish this performance improvement, ILE calculates the first array element address outside the loop and saves the value for use inside the loop.

Take the following example:
   DCL ARR[1000] INTEGER;
   DCL I INTEGER;
 
   I = init_expression;   /* Assume that init_expression evaluates
                             to -1 which is then assigned to I */
 
   /* More statements */
 
   WHILE ( I < limit_expression )
 
     I = I + 1;
 
     /* Some statements in the while loop */
 
     ARR[I] = some_expression;
 
     /* Other statements in the while loop */
 
   END;

If a reference to ARR[init_expression] would have produced an incorrect array index, this example can cause an MCH3601 exception. This is because ILE attempted to calculate the first array element address before entering the WHILE loop.

If you receive MCH3601 exceptions at optimization level 30 (*FULL) or 40, look for the following situation:
  1. You have a loop that increments a variable before it uses the variable as an array element index.
  2. The initial value of the index variable on entrance to the loop is negative.
  3. A reference to the array using the initial value of the variable is not valid.
When these conditions exist, it may be possible to do the following so that optimization level 30 (*FULL) or 40 can still be used:
  1. Move the part of the program that increments the variable to the bottom of the loop.
  2. Change the references to the variables as needed.
The previous example would be changed as follows:
   I = init_expression + 1;
 
   WHILE ( I < limit_expression + 1 )
 
     ARR[I] = some_expression;
 
     I = I + 1;
 
   END;

If this change is not possible, reduce the optimization level from 30 (*FULL) or 40 to 20 (*BASIC) or 10 (*NONE).