nir: Assert that we don't shrink bit-sizes in nir_lower_bit_size()
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 19 May 2023 00:15:04 +0000 (17:15 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 19 May 2023 22:44:37 +0000 (22:44 +0000)
The idea of this pass is to promote small bit-sizes to larger, supported
bit-sizes for certain operations.  It doesn't handle emulating large
bit-size operations on smaller bit-sizes; passes like nir_lower_int64
and nir_lower_doubles handle that.

So, assert that we aren't shrinking the bit-size, as this will almost
certainly produce incorrect results.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23123>

src/compiler/nir/nir_lower_bit_size.c

index 2b221bf..9d81bb3 100644 (file)
@@ -33,6 +33,8 @@
 static nir_ssa_def *convert_to_bit_size(nir_builder *bld, nir_ssa_def *src,
                                         nir_alu_type type, unsigned bit_size)
 {
+   assert(src->bit_size < bit_size);
+
    /* create b2i32(a) instead of i2i32(b2i8(a))/i2i32(b2i16(a)) */
    nir_alu_instr *alu = nir_src_as_alu_instr(nir_src_for_ssa(src));
    if ((type & (nir_type_uint | nir_type_int)) && bit_size == 32 &&