...
original loop
|
|---|
for (int i = init, i < limit; i += stride) { // loop with array range check ... if (scale*i + offset < a.length) { // array range check <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="650022d0087cf8f8-15e6a121-4f314a0f-b45382fb-0ca208eb546899980f145f05"><ac:plain-text-body><![CDATA[ ... a[scale*i+offset] ... ]]></ac:plain-text-body></ac:structured-macro> } else raise_uncommon_trap(); ... } |
after loop predication
|
|---|
if ( scale * imax + offset < a.length ) { // loop predicate. imax is the maximum value of i where init <= i < limit for (int i = init, i < limit; i += stride) { // loop without array range check ... <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c8ef1b9e212f50b7-a1a00060-4c07469f-a3cdb771-97a7a1d14f6de044c0f2c976"><ac:plain-text-body><![CDATA[ ... a[scale*i+offset] ... ]]></ac:plain-text-body></ac:structured-macro> ... } } else raise_uncommon_trap();
|
...
Loop Predication Advantages
Source Code
1. The parser inserts a dummy loop predicate on each path to the loop head block (Parse::add_predicate in parse1.cpp)
2. The loop optimizer analyzes the loop and promote the checks outside the loop (IdealLoopTree::loop_predication in loopTransformation.cpp)
3. Loop predication is controlled by the -XX flag UseLoopPredicate. -XX:+TraceLoopPredicate turns on the debug engine for loop predication in debug VM.