When a loop contains an IF statement whose condition does not change from one iteration to another, the same test must be repeated for every iteration. The code can often be made more efficient by floating the IF outside the loop and putting the THEN and ELSE sections into their own loops.
This gets more complicated when there is other code in the loop, since a copy of it must be included in both the THEN and ELSE loops. For example:
DO I = ... section-1 IF ( ) THEN section-2 ELSE section-3 ENDIF section-4 ENDDO
Becomes:
IF ( ) THEN DO I = ... section-1 section-2 section-4 ENDDO ELSE DO I = ... section-1 section-3 section-4 ENDDO ENDIF
When sections 1
and 4
are large, the extra
code generated can slow a program down through cache contention,
extra paging, and so on, more than the reduced number of IF tests
speed it up. The -each_invariant_if_growth
switch
provides a maximum size in number of lines of executable code of
sections 1
and 4
below which KAP tries to
float an invariant IF outside a loop.
This can be controlled on a loop-by-loop basis with the
C*$* each_invariant_if_growth
(<integer>) directive.
The total amount of additional code generated in a program
unit through invariant-IF floating can be limited with the
-max_invariant_if_growth
switch.
Copyright © Digital Equipment Corporation. 1997.
All Rights Reserved.