nir: Support upper bound of unsigned bit size conversions.
authorTimur Kristóf <timur.kristof@gmail.com>
Fri, 23 Apr 2021 06:48:46 +0000 (08:48 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 12 May 2021 13:47:04 +0000 (13:47 +0000)
These allow us to generate slightly better code in some cases,
eg. multiplications in ACO.

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10740>

src/compiler/nir/nir_range_analysis.c

index 7563278..1d7eb99 100644 (file)
@@ -1457,6 +1457,15 @@ nir_unsigned_upper_bound(nir_shader *shader, struct hash_table *range_ht,
       case nir_op_f2u32:
       case nir_op_fmul:
          break;
+      case nir_op_u2u1:
+      case nir_op_u2u8:
+      case nir_op_u2u16:
+      case nir_op_u2u32:
+         if (nir_ssa_scalar_chase_alu_src(scalar, 0).def->bit_size > 32) {
+            /* If src is >32 bits, return max */
+            return max;
+         }
+         break;
       default:
          return max;
       }
@@ -1570,6 +1579,12 @@ nir_unsigned_upper_bound(nir_shader *shader, struct hash_table *range_ht,
             memcpy(&res, &max_f, 4);
          }
          break;
+      case nir_op_u2u1:
+      case nir_op_u2u8:
+      case nir_op_u2u16:
+      case nir_op_u2u32:
+         res = MIN2(src0, max);
+         break;
       default:
          res = max;
          break;