On Sun, Jul 13, 2014 at 10:50 AM, Thomas Helland <thomashellan...@gmail.com> wrote: > I've considered writing an algebraic optimization to convert > this into an ir_binop_pow. If my understanding is correct the backend > will then implement this in a similar fashion as above if it does not > have a native pow() instruction. > > If, on the other hand, we have a pow() instruction, my guess is > we'd see reduced instruction-counts. > > Is my understanding correct? Is this something that's worth doing?
Yes and yes :) It's something I've thought about doing for a while. The only hang-up is that we don't get nice expression trees to match in opt_algebraic. Ideally, we'd get an ir_instruction with an rvalue that looked like (assign (xyz) (var_ref r3) (expression vec3 log2 (expression vec3 * (expression vec3 exp2 (swiz xyz (var_ref r3))) (constant vec3 (2.200000 2.200000 2.200000))))) and then the bit of code in opt_algebraic is simple. Unfortunately, r3 is likely a vec4 and is used repeatedly throughout the shader for many unrelated things. If we were able to split up these variables (i.e., recognize that the use of r3 for log2/mul/exp2 is a distinct live range from the other uses of r3, and give it a new variable name) then tree grafting would be able to give us the expression tree that we want. That would let a lot of existing optimization passes perform better as well. Ken and I worked on this kind of pass in the i965 backend [0]. It looked for full register writes outside of control flow, assigned the result to a new register, and rewrote future uses of the old with the new register. Something like that at the GLSL IR level would do the trick. One problem to solve is how to handle partial writes of variables, since in the case you brought up the shader only uses 3 components of a vec4, but they're still a distinct live range. I'd be happy to help if you're interested in giving this a shot. I'm always on Freenode (#dri-devel, #intel-gfx). [0] http://lists.freedesktop.org/archives/mesa-dev/2014-April/057812.html _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev