Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Loop

...

Predication

...

Loop

...

Predication

...

is

...

an

...

optimization

...

in

...

C2.

...

The

...

general

...

idea

...

is

...

to

...

insert

...

a

...

predicate

...

on

...

the

...

entry

...

path

...

to

...

a

...

loop,

...


and

...

raise

...

a

...

uncommon

...

trap

...

if

...

the

...

check

...

of

...

the

...

condition

...

fails.

...

The

...

condition

...

checks

...

are

...

promoted

...

from

...

inside

...

the

...


loop

...

body,

...

and

...

thus

...

the

...

checks

...

inside

...

the

...

loop

...

could

...

be

...

eliminated.

...

Currently,

...

loop

...

predication

...

optimization

...

has

...


been

...

applied

...

to

...

remove

...

array

...

range

...

check,

...

null

...

checks

...

and

...

array

...

checks

...

in

...

loops.

...

  Loop Predication for Array Range Check Elimination

    Use loop predicate to remove array range checks in a loop.

   

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="5c9ef9c4-0540-4077-87ff-94bfc3c195b7"><ac:plain-text-body><![CDATA[        ... a[scale*i+offset

...

]

...

...

...


]]></ac:plain-text-body></ac:structured-macro>
    } else raising_uncommon_trap();

...


    ...

...


}

after loop predication

if ( scale * imax + offset < a.length )

...

{  // loop predicate
    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="326791a3-ba6c-4375-879e-49b7aa0d5ffe"><ac:plain-text-body><![CDATA[         ... a[scale*i+offset] ...
]]></ac:plain-text-body></ac:structured-macro>
         ...
    }
} else raise_uncommon_trap();