Banerjee test

In compiler theory, the Banerjee test is a dependence test.

The Banerjee test assumes that all loop indices are independent, however in reality, this is often not true.

The Banerjee test is a conservative test.

That is, it will not break a dependence that does not exist.

This means that the only thing the test can guarantee is the absence of a dependence.

For a loop of the form: A true dependence exists between statement s1 and statement s2 if and only if :

An anti dependence exists between statement s1 and statement s2 if and only if :

For a loop of the form: A true dependence exists between statement s1 and statement s2 if and only if :

An example of Banerjee's test follows below.

The loop to be tested for dependence is: Let

{\displaystyle {\begin{array}{lcr}f(i)\ =\ i+9\\g(j)\ =\ j+0.\end{array}}}

{\displaystyle {\begin{array}{lcr}a_{0}=9\ ,\ a_{1}=1,\\b_{0}=0\ ,\ b_{1}=1.\\\end{array}}}

max

max

min

min

{\displaystyle {\begin{array}{lcr}U_{\max }\ =\ \max \left\{a_{1}\times i-b_{1}\times j\right\}~~{\textrm {when}}~~0\leq j

max

min

{\displaystyle {\begin{array}{lcr}U_{\max }\ =\ 9-0=9\\L_{\min }\ =\ 1-0=1.\\\end{array}}}

Now, the bounds on

Clearly, -9 is not inside the bounds, so the antidependence is broken.

max

min

{\displaystyle {\begin{array}{lcr}U_{max}\ =\ \max \left\{a_{1}\times i-b_{1}\times j\right\}~~{\textrm {when}}~~\leq i\leq j

{\displaystyle {\begin{array}{lcr}U_{max}\ =\ 9-9=0\\L_{min}\ =\ 0-9=-9.\\\end{array}}}

Clearly, -9 is inside the bounds, so the true dependence is not broken.

Because the antidependence was broken, we can assert that anti dependence does not exist between the statements.

Because the true dependence was not broken, we do not know if a true dependence exists between the statements.

Therefore, the loop is parallelisable, but the statements must be executed in order of their (potential) true dependence.