...
original loop |
---|
for (int i = init, i < limit; i += stride) { // loop with array range check |
after loop predication |
---|
if ( scale * imax + offset < a.length ) { // loop predicate. imax is the maximum value of i where init <= i < limit |
...
Compared with the iteration range splitting based check elimination, loop predication has the following advantages:
1. Loop predication can be applied to outer loops without code size increment.
2. With loop predication, the check can be eliminated in the entire iteration space.
3. Loop predication can be applied to loops with calls
4. (for future work) Loop predication provides a unified interface that can be implemented (extended) to replace the existing iteration range
splitting based check eliminations (loop peeling, partial peeling, range check elimination)
Source Code
1. The parser inserts a dummy loop predicate on each path to the loop head block (Parse::add_predicate in parse1.cpp)
...