i965/fs: Add support for global copy propagation.
authorEric Anholt <eric@anholt.net>
Tue, 30 Oct 2012 18:09:59 +0000 (11:09 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 8 Nov 2012 22:50:32 +0000 (14:50 -0800)
commit177c82555b24a80c15c34315ff17437cc39d1ba5
tree39ecf2ef08bbe0725b9a7089a58f81c80f82bcbf
parent9785ae0973cc206afc36dbc7d5b9553f92d06b47
i965/fs: Add support for global copy propagation.

It is common for complicated shaders, particularly code-generated ones, to
have a big array of uniforms or attributes, and a prologue in the shader that
dereferences from the big array to more informatively-named local variables.
Then there will be some small control flow operation (like a ? : statement),
and then use of those informatively-named variables.  We were emitting extra
MOVs in these cases, because copy propagation couldn't reach across control
flow.

Instead, implement dataflow analysis on the output of the first copy
propagation pass and re-run it to propagate those extra MOVs out.

On one future Steam release, reduces VS+FS instruction count from 42837 to
41437.  No statistically significant performance difference (n=48), though, at
least at the low resolution I'm running it at.

shader-db results:

total instructions in shared programs: 722170 -> 702545 (-2.72%)
instructions in affected programs:     260618 -> 240993 (-7.53%)

Some shaders do get hurt by up to 2 instructions, because a choice to copy
propagate instead of coalesce or something like that results in a dead write
sticking around.  Given that we already have instances of those instructions
in the affected programs (particularly unigine), we should just improve dead
code elimination to fix the problem.
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp