From 50bead32b150a869f1c17efbee8476114d1462a7 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Tue, 12 May 2020 11:10:18 +0100 Subject: [PATCH] nir/opt_if: run opt_peel_loop_initial_if after all other optimizations 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 Reviewed-by: Jason Ekstrand Fixes: 52c8bc0130a ('nir: make opt_if_loop_terminator() less strict') Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2943 Part-of: --- .gitlab-ci/deqp-radv-fiji-aco-fails.txt | 3 -- .gitlab-ci/deqp-radv-navi10-aco-fails.txt | 1 - .gitlab-ci/deqp-radv-pitcairn-aco-fails.txt | 3 -- .gitlab-ci/deqp-radv-polaris10-aco-fails.txt | 3 -- .gitlab-ci/deqp-radv-raven-aco-fails.txt | 1 - .gitlab-ci/deqp-radv-vega10-aco-fails.txt | 1 - src/compiler/nir/nir_opt_if.c | 49 ++++++++++++++++++-- 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci/deqp-radv-fiji-aco-fails.txt b/.gitlab-ci/deqp-radv-fiji-aco-fails.txt index 66b11f7b7b2..3754ad5e9fc 100644 --- a/.gitlab-ci/deqp-radv-fiji-aco-fails.txt +++ b/.gitlab-ci/deqp-radv-fiji-aco-fails.txt @@ -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 diff --git a/.gitlab-ci/deqp-radv-navi10-aco-fails.txt b/.gitlab-ci/deqp-radv-navi10-aco-fails.txt index fb0bfc9e184..39b0e5bbabb 100644 --- a/.gitlab-ci/deqp-radv-navi10-aco-fails.txt +++ b/.gitlab-ci/deqp-radv-navi10-aco-fails.txt @@ -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 diff --git a/.gitlab-ci/deqp-radv-pitcairn-aco-fails.txt b/.gitlab-ci/deqp-radv-pitcairn-aco-fails.txt index 1a9895fbda1..7541df0c183 100644 --- a/.gitlab-ci/deqp-radv-pitcairn-aco-fails.txt +++ b/.gitlab-ci/deqp-radv-pitcairn-aco-fails.txt @@ -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 diff --git a/.gitlab-ci/deqp-radv-polaris10-aco-fails.txt b/.gitlab-ci/deqp-radv-polaris10-aco-fails.txt index dd4f00a7166..ae8d825f416 100644 --- a/.gitlab-ci/deqp-radv-polaris10-aco-fails.txt +++ b/.gitlab-ci/deqp-radv-polaris10-aco-fails.txt @@ -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 diff --git a/.gitlab-ci/deqp-radv-raven-aco-fails.txt b/.gitlab-ci/deqp-radv-raven-aco-fails.txt index fb0bfc9e184..39b0e5bbabb 100644 --- a/.gitlab-ci/deqp-radv-raven-aco-fails.txt +++ b/.gitlab-ci/deqp-radv-raven-aco-fails.txt @@ -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 diff --git a/.gitlab-ci/deqp-radv-vega10-aco-fails.txt b/.gitlab-ci/deqp-radv-vega10-aco-fails.txt index fb0bfc9e184..39b0e5bbabb 100644 --- a/.gitlab-ci/deqp-radv-vega10-aco-fails.txt +++ b/.gitlab-ci/deqp-radv-vega10-aco-fails.txt @@ -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 diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c index 9460cefb79b..f2dec89ba7e 100644 --- a/src/compiler/nir/nir_opt_if.c +++ b/src/compiler/nir/nir_opt_if.c @@ -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; -- 2.30.2