From 6e53be2a0abe8f347ec466ade6df8a033b3446f1 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 23 May 2024 10:11:26 -0700 Subject: [PATCH] nir/search: Fix is_16_bits for vectors Require that all elements of a vector be representable as either int16_t or uint16_t. Reviewed-by: Jordan Justen Fixes: 7ef45e661f4 ("intel/fs: Add constant propagation for ADD3") Part-of: --- src/compiler/nir/nir_search_helpers.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index 570af8c5fbc..06d88eb9dc4 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -355,12 +355,30 @@ is_16_bits(UNUSED struct hash_table *ht, const nir_alu_instr *instr, if (!nir_src_is_const(instr->src[src].src)) return false; + /* All elements must be representable as int16_t or uint16_t. */ + bool must_be_signed = false; + bool must_be_unsigned = false; + for (unsigned i = 0; i < num_components; i++) { const int64_t val = nir_src_comp_as_int(instr->src[src].src, swizzle[i]); if (val > 0xffff || val < -0x8000) return false; + + if (val < 0) { + if (must_be_unsigned) + return false; + + must_be_signed = true; + } + + if (val > 0x7fff) { + if (must_be_signed) + return false; + + must_be_unsigned = true; + } } return true;