[Mesa-dev] Mesa (shader-work): glsl: teach loop analysis that array dereferences are bounds on the index

Luca Barbieri luca at luca-barbieri.com
Wed Sep 8 12:30:56 PDT 2010

> I think some of the danger lies in constructs like:
>        for (int i = 0; i < limit; i++)
>                if (i < gl_TexCoord.length())
>                        do_something_with(gl_TexCoord[i]);
>                else
>                        do_something_else();

Yes, you are right.

What we should logically do is apply this optimization, but only if
the dereference is guaranteed to be executed.
A simple method seems to be to check that it is not inside an if, and
is not preceded by any code with continue or break.

Presumably the induction variable code needs to check this too, since
otherwise this infinite loop would be broken too:

for (int i = 0;; i++)
   if(i >= 2)

   if(i >= 3)

> What is the intended lifetime of these
> instructions?  It appears that it's the same as the loop_state object
> (or the loop_variable_state objects).  If that's the case, one of those
> should probably be used as the memory context instead of ir.

Is the way talloc is used and works documented anywhere?
In particular, calling placement new with any part of the IR is always
equivalent, right?

More information about the mesa-dev mailing list