nir/opt_if: run opt_peel_loop_initial_if after all other optimizations
authorRhys Perry <pendingchaos02@gmail.com>
Tue, 12 May 2020 10:10:18 +0000 (11:10 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 19 May 2020 17:46:38 +0000 (17:46 +0000)
Fixes dEQP-VK.graphicsfuzz.loops-ifs-continues-call with RADV.

opt_if_loop_terminator can cause this optimization or
opt_if_simplification to be run on the non-SSA code.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Fixes: 52c8bc0130a ('nir: make opt_if_loop_terminator() less strict')
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2943
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4757>

.gitlab-ci/deqp-radv-fiji-aco-fails.txt
.gitlab-ci/deqp-radv-navi10-aco-fails.txt
.gitlab-ci/deqp-radv-pitcairn-aco-fails.txt
.gitlab-ci/deqp-radv-polaris10-aco-fails.txt
.gitlab-ci/deqp-radv-raven-aco-fails.txt
.gitlab-ci/deqp-radv-vega10-aco-fails.txt
src/compiler/nir/nir_opt_if.c

index 66b11f7b7b2560b92276ee793c34c8475ca31cf6..3754ad5e9fc8f2734f84ce7a9d167fa5a46be644 100644 (file)
@@ -11,9 +11,6 @@ dEQP-VK.glsl.builtin.precision.asin.highp.vec4
 # CTS bug (list of extensions not up-to-date).
 dEQP-VK.info.device_extensions
 
-# ACO specific issues.
-dEQP-VK.graphicsfuzz.loops-ifs-continues-call
-
 # Interesting failures...
 dEQP-VK.renderpass2.depth_stencil_resolve.image_2d_16_64_6.samples_2.d32_sfloat_s8_uint.stencil_max
 dEQP-VK.renderpass2.depth_stencil_resolve.image_2d_16_64_6.samples_2.d32_sfloat_s8_uint.stencil_min
index fb0bfc9e184540ebd0e868ca60742a5d52331ee7..39b0e5bbabbf2ec429583477b78a7a8da6c01f4c 100644 (file)
@@ -10,4 +10,3 @@ dEQP-VK.info.device_extensions
 # ACO specific issues.
 dEQP-VK.transform_feedback.simple.multistreams_1
 dEQP-VK.transform_feedback.simple.multistreams_3
-dEQP-VK.graphicsfuzz.loops-ifs-continues-call
index 1a9895fbda1b2a9adc31fc82e6e18c1d5674bdf0..7541df0c183c5699608d10dd9685c68a13f5c705 100644 (file)
@@ -6,6 +6,3 @@ dEQP-VK.glsl.builtin.precision.asin.highp.vec4
 
 # CTS bug (list of extensions not up-to-date).
 dEQP-VK.info.device_extensions
-
-# ACO specific issues.
-dEQP-VK.graphicsfuzz.loops-ifs-continues-call
index dd4f00a7166efd3963a4568d202add8505a2780d..ae8d825f4164d6ed9a89ac8ffcc7bdb2be848a2d 100644 (file)
@@ -10,6 +10,3 @@ dEQP-VK.glsl.builtin.precision.asin.highp.vec4
 
 # CTS bug (list of extensions not up-to-date).
 dEQP-VK.info.device_extensions
-
-# ACO specific issues.
-dEQP-VK.graphicsfuzz.loops-ifs-continues-call
index fb0bfc9e184540ebd0e868ca60742a5d52331ee7..39b0e5bbabbf2ec429583477b78a7a8da6c01f4c 100644 (file)
@@ -10,4 +10,3 @@ dEQP-VK.info.device_extensions
 # ACO specific issues.
 dEQP-VK.transform_feedback.simple.multistreams_1
 dEQP-VK.transform_feedback.simple.multistreams_3
-dEQP-VK.graphicsfuzz.loops-ifs-continues-call
index fb0bfc9e184540ebd0e868ca60742a5d52331ee7..39b0e5bbabbf2ec429583477b78a7a8da6c01f4c 100644 (file)
@@ -10,4 +10,3 @@ dEQP-VK.info.device_extensions
 # ACO specific issues.
 dEQP-VK.transform_feedback.simple.multistreams_1
 dEQP-VK.transform_feedback.simple.multistreams_3
-dEQP-VK.graphicsfuzz.loops-ifs-continues-call
index 9460cefb79be9dbe68d04879f0c662e9f86e6390..f2dec89ba7e334ca4b9fcb350cd548557c0d983e 100644 (file)
@@ -1334,7 +1334,6 @@ opt_if_cf_list(nir_builder *b, struct exec_list *cf_list,
          progress |= opt_if_cf_list(b, &loop->body,
                                     aggressive_last_continue);
          progress |= opt_simplify_bcsel_of_phi(b, loop);
-         progress |= opt_peel_loop_initial_if(loop);
          progress |= opt_if_loop_last_continue(loop,
                                                aggressive_last_continue);
          break;
@@ -1348,6 +1347,37 @@ opt_if_cf_list(nir_builder *b, struct exec_list *cf_list,
    return progress;
 }
 
+static bool
+opt_peel_loop_initial_if_cf_list(struct exec_list *cf_list)
+{
+   bool progress = false;
+   foreach_list_typed(nir_cf_node, cf_node, node, cf_list) {
+      switch (cf_node->type) {
+      case nir_cf_node_block:
+         break;
+
+      case nir_cf_node_if: {
+         nir_if *nif = nir_cf_node_as_if(cf_node);
+         progress |= opt_peel_loop_initial_if_cf_list(&nif->then_list);
+         progress |= opt_peel_loop_initial_if_cf_list(&nif->else_list);
+         break;
+      }
+
+      case nir_cf_node_loop: {
+         nir_loop *loop = nir_cf_node_as_loop(cf_node);
+         progress |= opt_peel_loop_initial_if_cf_list(&loop->body);
+         progress |= opt_peel_loop_initial_if(loop);
+         break;
+      }
+
+      case nir_cf_node_function:
+         unreachable("Invalid cf type");
+      }
+   }
+
+   return progress;
+}
+
 /**
  * These optimisations depend on nir_metadata_block_index and therefore must
  * not do anything to cause the metadata to become invalid.
@@ -1402,17 +1432,26 @@ nir_opt_if(nir_shader *shader, bool aggressive_last_continue)
       nir_metadata_preserve(function->impl, nir_metadata_block_index |
                             nir_metadata_dominance);
 
-      if (opt_if_cf_list(&b, &function->impl->body,
-                         aggressive_last_continue)) {
-         nir_metadata_preserve(function->impl, nir_metadata_none);
+      bool preserve = true;
+
+      if (opt_if_cf_list(&b, &function->impl->body, aggressive_last_continue)) {
+         preserve = false;
+         progress = true;
+      }
+
+      if (opt_peel_loop_initial_if_cf_list(&function->impl->body)) {
+         preserve = false;
+         progress = true;
 
          /* If that made progress, we're no longer really in SSA form.  We
           * need to convert registers back into SSA defs and clean up SSA defs
           * that don't dominate their uses.
           */
          nir_lower_regs_to_ssa_impl(function->impl);
+      }
 
-         progress = true;
+      if (preserve) {
+         nir_metadata_preserve(function->impl, nir_metadata_none);
       } else {
    #ifndef NDEBUG
          function->impl->valid_metadata &= ~nir_metadata_not_properly_reset;