nir: Add a lowering pass to split 64bit phis
[mesa.git] / src / compiler / nir / nir_opt_if.c
index 4b2d0159baba5330648d4d561d283a25c9335831..a97126cb0d8a715fb351436eb18bbdc6394bafe3 100644 (file)
@@ -275,7 +275,7 @@ alu_instr_is_comparison(const nir_alu_instr *alu)
    case nir_op_flt32:
    case nir_op_fge32:
    case nir_op_feq32:
-   case nir_op_fne32:
+   case nir_op_fneu32:
    case nir_op_ilt32:
    case nir_op_ult32:
    case nir_op_ige32:
@@ -630,7 +630,7 @@ opt_simplify_bcsel_of_phi(nir_builder *b, nir_loop *loop)
     * bcsel that must come before any break.
     *
     * For more details, see
-    * https://gitlab.freedesktop.org/mesa/mesa/merge_requests/170#note_110305
+    * https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/170#note_110305
     */
    nir_foreach_instr_safe(instr, header_block) {
       if (instr->type != nir_instr_type_alu)
@@ -931,6 +931,17 @@ opt_if_simplification(nir_builder *b, nir_if *nif)
    nir_block *then_block = nir_if_last_then_block(nif);
    nir_block *else_block = nir_if_last_else_block(nif);
 
+   if (nir_block_ends_in_jump(else_block)) {
+      /* Even though this if statement has a jump on one side, we may still have
+       * phis afterwards.  Single-source phis can be produced by loop unrolling
+       * or dead control-flow passes and are perfectly legal.  Run a quick phi
+       * removal on the block after the if to clean up any such phis.
+       */
+      nir_block *const next_block =
+         nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node));
+      nir_opt_remove_phis_block(next_block);
+   }
+
    rewrite_phi_predecessor_blocks(nif, then_block, else_block, else_block,
                                   then_block);
 
@@ -1451,9 +1462,7 @@ nir_opt_if(nir_shader *shader, bool aggressive_last_continue)
       if (preserve) {
          nir_metadata_preserve(function->impl, nir_metadata_none);
       } else {
-   #ifndef NDEBUG
-         function->impl->valid_metadata &= ~nir_metadata_not_properly_reset;
-   #endif
+         nir_metadata_preserve(function->impl, nir_metadata_all);
       }
    }