[Mesa-dev] [PATCH] nir: Implement optional b2f->iand lowering

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Mon Apr 30 08:36:06 UTC 2018


Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>

On Sun, Apr 29, 2018 at 8:19 PM, Alyssa Rosenzweig <alyssa at rosenzweig.io> wrote:
> This pass is required by the Midgard compiler; our instruction set uses
> NIR-style booleans (~0 for true) but lacks a dedicated b2f instruction.
> Normally, this lowering pass would be implemented in a backend-specific
> algebraic pass, but this conflicts with the existing iand->b2f pass in
> nir_opt_algebraic.py, hanging the compiler. This patch thus makes the
> existing pass optional (default on -- all other backends should remain
> unaffected), adding an optional pass for lowering the opposite
> direction.
>
> Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
> ---
>  src/compiler/nir/nir.h                | 3 +++
>  src/compiler/nir/nir_opt_algebraic.py | 3 ++-
>  2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index de935392a2..135018004f 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -1862,6 +1862,9 @@ typedef struct nir_shader_compiler_options {
>     /** enables rules to lower idiv by power-of-two: */
>     bool lower_idiv;
>
> +   /* lower b2f to iand */
> +   bool lower_b2f;
> +
>     /* Does the native fdot instruction replicate its result for four
>      * components?  If so, then opt_algebraic_late will turn all fdotN
>      * instructions into fdot_replicatedN instructions.
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index 761c61ac0b..7da09ee918 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -318,7 +318,8 @@ optimizations = [
>     (('imul', ('b2i', a), ('b2i', b)), ('b2i', ('iand', a, b))),
>     (('fmul', ('b2f', a), ('b2f', b)), ('b2f', ('iand', a, b))),
>     (('fsat', ('fadd', ('b2f', a), ('b2f', b))), ('b2f', ('ior', a, b))),
> -   (('iand', 'a at bool', 1.0), ('b2f', a)),
> +   (('iand', 'a at bool', 1.0), ('b2f', a), '!options->lower_b2f'),
> +   (('b2f at 32', a), ('iand', a, 1.0), 'options->lower_b2f'),
>     # True/False are ~0 and 0 in NIR.  b2i of True is 1, and -1 is ~0 (True).
>     (('ineg', ('b2i at 32', a)), a),
>     (('flt', ('fneg', ('b2f', a)), 0), a), # Generated by TGSI KILL_IF.
> --
> 2.16.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list