[Mesa-dev] [PATCH 2/5] nir: Allow nir_opt_algebraic to see booleanness through &&, ||, !.

Connor Abbott cwabbott0 at gmail.com
Fri Feb 20 14:48:54 PST 2015


On Fri, Feb 20, 2015 at 3:04 PM, Eric Anholt <eric at anholt.net> wrote:
> We have some useful optimizations to drop things like 'ine a, 0' on a
> boolean argument, but if 'a' came from logical operations on bools, it
> couldn't tell.  These kinds of constructs appear as a result of TGSI->NIR
> quite frequently (at least with if flattening), so being a little more
> aggressive in detecting booleans can pay off.
>
> vc4 results:
> total instructions in shared programs: 40207 -> 39881 (-0.81%)
> instructions in affected programs:     6677 -> 6351 (-4.88%)
> ---
>  src/glsl/nir/nir_search.c | 29 ++++++++++++++++++++++++++++-
>  1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/src/glsl/nir/nir_search.c b/src/glsl/nir/nir_search.c
> index 4671931..d12b6ab 100644
> --- a/src/glsl/nir/nir_search.c
> +++ b/src/glsl/nir/nir_search.c
> @@ -39,6 +39,32 @@ match_expression(const nir_search_expression *expr, nir_alu_instr *instr,
>
>  static const uint8_t identity_swizzle[] = { 0, 1, 2, 3 };
>
> +static bool alu_instr_is_bool(nir_alu_instr *instr);
> +
> +static bool
> +src_is_bool(nir_src src)
> +{
> +   if (!src.is_ssa)
> +      return false;
> +   if (src.ssa->parent_instr->type != nir_instr_type_alu)
> +      return false;
> +   return alu_instr_is_bool((nir_alu_instr *)src.ssa->parent_instr);
> +}
> +
> +static bool
> +alu_instr_is_bool(nir_alu_instr *instr)
> +{
> +   switch (instr->op) {
> +   case nir_op_iand:
> +   case nir_op_ior:

Add nir_op_ixor here?

> +      return src_is_bool(instr->src[0].src) && src_is_bool(instr->src[1].src);
> +   case nir_op_inot:
> +      return src_is_bool(instr->src[0].src);
> +   default:
> +      return nir_op_infos[instr->op].output_type == nir_type_bool;
> +   }
> +}
> +
>  static bool
>  match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
>              unsigned num_components, const uint8_t *swizzle,
> @@ -89,7 +115,8 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
>              nir_alu_instr *src_alu =
>                 nir_instr_as_alu(instr->src[src].src.ssa->parent_instr);
>
> -            if (nir_op_infos[src_alu->op].output_type != var->type)
> +            if (nir_op_infos[src_alu->op].output_type != var->type &&
> +                !(var->type == nir_type_bool && alu_instr_is_bool(src_alu)))
>                 return false;
>           }
>
> --
> 2.1.4
>
> _______________________________________________
> 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