During vertex processing with 4x4 matrices, we might stack multiple transformations like projection, model-world, world-camera, etc. by doing something like this:
$$v_{final} = T_N \cdot ... \cdot T_1 \cdot T_0 \cdot v$$
Now from the GLSL specs (section 5.1), I get that the operator associativity is "left to right". So this:
$$v_{final} = T_2 \cdot T_1 \cdot T_0 \cdot v$$
is equivalent to:
$$v_{final} = ((T_2 \cdot T_1) \cdot T_0) \cdot v$$
However, as matrix multiplication is associative, the result does not change if we write:
$$v_{final} = T_2 \cdot (T_1 \cdot (T_0 \cdot v))$$
While both versions yield the same result, the second version should (at least in theory) be much cheaper to compute since it incorporates 3 matrix-vector multiplications while the first version does 2 matrix-matrix multiplications and a final matrix-vector multiplication.
So my question is, does enforcing the order by adding extra parenthesis really boost performance or is the GLSL compiler usually smart enough to figure out, that the order of operations does not matter for the result and he can reorder the executions for performance even though the specs say "left to right" associativity?
Additional Note: I specially mentioned 4x4 matrices, because if you use 3x3 matrices or quaternions, you have to use parenthesis anyways because of the addition of the translations.
While both versions yield the same result
<-- no, they really don't. Not with real float/double values which have limited precision. I can't say for certain that's the reason GLSL is specified that way however, which is why I'm not writing this as an answer. $\endgroup$