[Mesa-dev] [PATCH 2/6] nir: Prehash in instr_set to avoid hashing twice
Thomas Helland
thomashelland90 at gmail.com
Mon May 22 21:18:09 UTC 2017
2017-05-22 20:55 GMT+02:00 Thomas Helland <thomashelland90 at gmail.com>:
> This should prove benefitial in the common case of inserting
> and not rewriting anything.
>
> V2: Use hash_instr directly instead of going through the function
> pointer embedded in the set
Threw some sysprof profiles at this patch. This should theoretically
be the "big winner" in this patch series, plus the string_to_uint_map
patch. The rationale being that the slower the hashing, the more
this will benefit us.
Results from sysprof:
Before:
nir_opt_cse 3.68%
hash_instr (on search) 0.28%
hash_instr (on insert) 0.26%
After:
nir_opt_cse 3.31%
hash_instr 0.28%
So we see the 0.26% spent in hash_instr on insert going away,
as we should expect, but interestingly the cumulative time
spent in nir_opt_cse drops 0.37% of the total, down to 3.31%.
For fun I also fired up the quadratic probing hash set that
I still haven't gotten around to finalizing. That brings us down
even further, bringing us under 3% of total for nir_opt_cse.
Shout out if there's any more tests I should do.
> ---
> src/compiler/nir/nir_instr_set.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c
> index 9cb9ed43e8..bdc3b02173 100644
> --- a/src/compiler/nir/nir_instr_set.c
> +++ b/src/compiler/nir/nir_instr_set.c
> @@ -508,7 +508,10 @@ 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);
> + uint32_t hash = hash_instr(instr);
> + struct set_entry *entry =
> + _mesa_set_search_pre_hashed(instr_set, hash, instr);
> +
> if (entry) {
> nir_ssa_def *def = nir_instr_get_dest_ssa_def(instr);
> nir_instr *match = (nir_instr *) entry->key;
> @@ -526,7 +529,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.13.0
>
More information about the mesa-dev
mailing list