Test promotion involves promoting a test out of the loop that encloses
it by replicating the containing loop for each branch of the test.
The replicated loops contain fewer tests than the originals, or
no tests at all, so the loops execute much faster. Multiple tests
are promoted, and copies of the loop are made for each test.
Test promotion
Consider the following Fortran loop:
DO I=1, 100 DO J=1, 100 IF(FOO .EQ. BAR) THEN A(I,J) = I + J ELSE A(I,J) = 0 ENDIF ENDDO ENDDO |
Test promotion (and loop interchange) produces the following
code:
IF(FOO .EQ. BAR) THEN DO J=1, 100 DO I=1, 100 A(I,J) = I + J ENDDO ENDDO ELSE DO J=1, 100 DO I=1, 100 A(I,J) = 0 ENDDO ENDDO ENDIF |
For loops containing large numbers of tests, loop replication
can greatly increase the size of the code.
Each DO loop in Fortran and
for loop in C and C++
whose bounds are not known at compile-time is implicitly tested
to check that the loop iterates at least once. This test may be
promoted, with the promotion noted in the Optimization Report. If
you see unexpected promotions in the report, this implicit testing
may be the cause. For more information on the Optimization Report,
see "Optimization Report," on page 151.