[Mesa-dev] [PATCH 1/4] nir: prehash instruction in nir_instr_set_add_or_rewrite()

Jason Ekstrand jason at jlekstrand.net
Wed Feb 13 14:40:18 UTC 2019


Yeah, I've always felt like this helper should use the pre-hashed versions. Rb

On February 13, 2019 02:00:44 Timothy Arceri <tarceri at itsqueeze.com> wrote:

> There is no need to hash the instruction twice, especially as we
> end up adding it in the majority of cases.
> ---
> src/compiler/nir/nir_instr_set.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/src/compiler/nir/nir_instr_set.c 
> b/src/compiler/nir/nir_instr_set.c
> index 060bd9eee0b..61476c0b03f 100644
> --- a/src/compiler/nir/nir_instr_set.c
> +++ b/src/compiler/nir/nir_instr_set.c
> @@ -588,10 +588,11 @@ nir_instr_set_add_or_rewrite(struct set *instr_set, 
> nir_instr *instr)
>    if (!instr_can_rewrite(instr))
>       return false;
>
> -   struct set_entry *entry = _mesa_set_search(instr_set, instr);
> -   if (entry) {
> +   uint32_t hash = hash_instr(instr);
> +   struct set_entry *e = _mesa_set_search_pre_hashed(instr_set, hash, instr);
> +   if (e) {
>       nir_ssa_def *def = nir_instr_get_dest_ssa_def(instr);
> -      nir_instr *match = (nir_instr *) entry->key;
> +      nir_instr *match = (nir_instr *) e->key;
>       nir_ssa_def *new_def = nir_instr_get_dest_ssa_def(match);
>
>       /* It's safe to replace an exact instruction with an inexact one as
> @@ -606,7 +607,7 @@ nir_instr_set_add_or_rewrite(struct set *instr_set, 
> nir_instr *instr)
>       return true;
>    }
>
> -   _mesa_set_add(instr_set, instr);
> +   _mesa_set_add_pre_hashed(instr_set, hash, instr);
>    return false;
> }
>
> --
> 2.20.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