[Mesa-dev] [PATCH] glsl: Optimize 1/exp(x) into exp(-x).
Ian Romanick
idr at freedesktop.org
Tue Feb 10 15:07:45 PST 2015
On 02/10/2015 01:11 PM, Jason Ekstrand wrote:
> Looks fine to me but why are we still adding algebraic optimizations to
> GLSL-IR?
Some cases, though this is not one, can slightly reduce memory usage.
GLSL IR will likely live on for some time as the pre-linked IR, so
that's a benefit we shouldn't discount.
While we are close to enabling NIR on the i965 scalar backend, that
leaves a lot of cases (including GS on all platforms, and VS on pre-GEN8
platforms) still needing love... not to mention non-Intel drivers.
> Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com
> <mailto:jason.ekstrand at intel.com>>
Also
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
> On Feb 10, 2015 12:36 PM, "Matt Turner" <mattst88 at gmail.com
> <mailto:mattst88 at gmail.com>> wrote:
>
> Lots of shaders divide by exp2(...) which we turn into a multiplication
> by the reciprocal. We can avoid the reciprocal by simply negating exp2's
> argument.
>
> total instructions in shared programs: 5947154 -> 5946695 (-0.01%)
> instructions in affected programs: 118661 -> 118202 (-0.39%)
> helped: 380
> ---
> src/glsl/opt_algebraic.cpp | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index c6f4a9c..616ed37 100644
> --- a/src/glsl/opt_algebraic.cpp
> +++ b/src/glsl/opt_algebraic.cpp
> @@ -747,6 +747,12 @@
> ir_algebraic_visitor::handle_expression(ir_expression *ir)
> if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp)
> return op_expr[0]->operands[0];
>
> + if (op_expr[0] && (op_expr[0]->operation == ir_unop_exp2 ||
> + op_expr[0]->operation == ir_unop_exp)) {
> + return new(mem_ctx) ir_expression(op_expr[0]->operation,
> ir->type,
> +
> neg(op_expr[0]->operands[0]));
> + }
> +
> /* While ir_to_mesa.cpp will lower sqrt(x) to rcp(rsq(x)), it
> does so at
> * its IR level, so we can always apply this transformation.
> */
> --
> 2.0.5
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list