imageworks/OpenShadingLanguage — pull request #268 by lgritz (2013-06-25 18:37:59+00:00)
Title: New peephole optimizations

New peephole optimizations:

(1) add A B C ; sub D A C => [add A B C ; ] assign D B
(the add is elided as well if A is not subsequently needed.)
And the same thing if the order of the add and sub are switched.

(2) OP A B... ; assign C A => OP C B...
As long as A is not subsequently used and OP is a "simple"
operation that fully overwrites A and writes to no other variables.

Looking at production shaders, the post-optimized number of instructions, symbols, connections, culled layers, and size of JITed code all improve by about 1-4% (depending on the thing being measured and varying from scene to scene). Rendering speed doesn't improve quite as much, but every little bit helps.