From 84eeecf8225c7f9bc1a2e6e3c5f2ef12f805b90d Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Tue, 10 Mar 2026 16:48:56 +0000 Subject: [PATCH] nir/range_analysis: use a dense array ministat (nir_analyze_fp_class): Difference at 95.0% confidence -201983 +/- 1064.87 -9.31575% +/- 0.0468505% (Student's t, pooled s = 1257.67) Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Part-of: --- src/compiler/nir/nir_range_analysis.c | 23 +++++++++++++---------- src/compiler/nir/nir_range_analysis.h | 3 +-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/compiler/nir/nir_range_analysis.c b/src/compiler/nir/nir_range_analysis.c index c1ea843ed2a..23af7db809e 100644 --- a/src/compiler/nir/nir_range_analysis.c +++ b/src/compiler/nir/nir_range_analysis.c @@ -201,7 +201,7 @@ fp_lookup(void *table, uint32_t key, uint32_t *value) { nir_fp_analysis_state *state = table; if (BITSET_TEST(state->bitset, key)) { - *value = *(uint16_t *)util_sparse_array_get(&state->arr, key); + *value = state->arr[key]; return true; } else { return false; @@ -214,7 +214,7 @@ fp_insert(void *table, uint32_t key, uint32_t value) nir_fp_analysis_state *state = table; BITSET_SET(state->bitset, key); state->max = MAX2(state->max, (int)key); - *(uint16_t *)util_sparse_array_get(&state->arr, key) = value; + state->arr[key] = value; } static fp_class_mask @@ -1393,22 +1393,25 @@ nir_create_fp_analysis_state(nir_function_impl *impl) { nir_fp_analysis_state state; state.impl = impl; - /* Over-allocate the bitset, so that we can keep using the allocated table memory + /* Over-allocate, so that we can keep using the allocated table memory * even when new SSA values are added. */ - state.size = BITSET_BYTES(impl->ssa_alloc + impl->ssa_alloc / 4u); + state.size = (impl->ssa_alloc + impl->ssa_alloc / 4u); state.max = -1; - state.bitset = calloc(state.size, 1); - util_sparse_array_init(&state.arr, 2, 256); + state.bitset = calloc(BITSET_BYTES(state.size), 1); + state.arr = malloc(state.size * sizeof(uint16_t)); return state; } void nir_invalidate_fp_analysis_state(nir_fp_analysis_state *state) { - if (BITSET_BYTES(state->impl->ssa_alloc) > state->size) { - state->size = BITSET_BYTES(state->impl->ssa_alloc + state->impl->ssa_alloc / 4u); + if (state->impl->ssa_alloc > state->size) { + state->size = state->impl->ssa_alloc + state->impl->ssa_alloc / 4u; + + free(state->arr); free(state->bitset); - state->bitset = calloc(state->size, 1); + state->arr = malloc(state->size * sizeof(uint16_t)); + state->bitset = calloc(BITSET_BYTES(state->size), 1); } else if (state->max >= 0) { memset(state->bitset, 0, BITSET_BYTES(state->max + 1)); } @@ -1418,7 +1421,7 @@ nir_invalidate_fp_analysis_state(nir_fp_analysis_state *state) void nir_free_fp_analysis_state(nir_fp_analysis_state *state) { - util_sparse_array_finish(&state->arr); + free(state->arr); free(state->bitset); } diff --git a/src/compiler/nir/nir_range_analysis.h b/src/compiler/nir/nir_range_analysis.h index 534e81d705f..91ed3ef09b4 100644 --- a/src/compiler/nir/nir_range_analysis.h +++ b/src/compiler/nir/nir_range_analysis.h @@ -24,7 +24,6 @@ #define _NIR_RANGE_ANALYSIS_H_ #include "util/bitset.h" -#include "util/sparse_array.h" #include "util/u_hash_table.h" #include "nir_defines.h" @@ -34,7 +33,7 @@ extern "C" { typedef struct { nir_function_impl *impl; - struct util_sparse_array arr; + uint16_t *arr; BITSET_WORD *bitset; uint32_t size; int32_t max;