nir: Add lowering from regular ALU conversions to the intrinsic

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6945>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index d102417..75da5ce 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4388,6 +4388,7 @@
 bool nir_lower_convert_alu_types(nir_shader *shader,
                                  bool (*should_lower)(nir_intrinsic_instr *));
 bool nir_lower_constant_convert_alu_types(nir_shader *shader);
+bool nir_lower_alu_covnersion_to_intrinsic(nir_shader *shader);
 bool nir_lower_int_to_float(nir_shader *shader);
 bool nir_lower_load_const_to_scalar(nir_shader *shader);
 bool nir_lower_read_invocation_to_scalar(nir_shader *shader);
diff --git a/src/compiler/nir/nir_lower_convert_alu_types.c b/src/compiler/nir/nir_lower_convert_alu_types.c
index d2594b8..0e94949 100644
--- a/src/compiler/nir/nir_lower_convert_alu_types.c
+++ b/src/compiler/nir/nir_lower_convert_alu_types.c
@@ -180,3 +180,27 @@
 {
    return nir_lower_convert_alu_types(shader, is_constant);
 }
+
+static bool
+is_alu_conversion(const nir_instr *instr, UNUSED const void *_data)
+{
+   return instr->type == nir_instr_type_alu &&
+          nir_op_infos[nir_instr_as_alu(instr)->op].is_conversion;
+}
+
+static nir_ssa_def *
+lower_alu_conversion(nir_builder *b, nir_instr *instr, UNUSED void *_data)
+{
+   nir_alu_instr *alu = nir_instr_as_alu(instr);
+   return nir_convert_alu_types(b, nir_ssa_for_alu_src(b, alu, 0),
+                                nir_op_infos[alu->op].input_types[0],
+                                nir_op_infos[alu->op].output_type,
+                                nir_rounding_mode_undef, false);
+}
+
+bool
+nir_lower_alu_covnersion_to_intrinsic(nir_shader *shader)
+{
+   return nir_shader_lower_instructions(shader, is_alu_conversion,
+                                        lower_alu_conversion, NULL);
+}