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 <jordan.l.justen@intel.com>
Fixes: 7ef45e661f ("intel/fs: Add constant propagation for ADD3")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29148>
This commit is contained in:
Ian Romanick
2024-05-23 10:11:26 -07:00
parent 22095c60bc
commit 6e53be2a0a

View File

@@ -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;