From b6a4172f1045783576c1bd2f97d4d8d9e031294d Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 16 Sep 2020 12:49:15 -0500 Subject: [PATCH] nir/lower_goto_ifs: Don't destroy SSA form in the process There are two issues here: 1. If there are any phi nodes, we'll make complete hash of them. This isn't likely actually a problem because spirv_to_nir doesn't generate any actual phi nodes today. However, if we start doing any other passes before this, we may have a problem. 2. Even without phi nodes, we may still break SSA form. This can happen if we ever have to stick a block inside a conditional to satisfy weird CFG constraints. Doing so can cause it to no longer look like it dominates some of its uses even though, at runtime, it's guaranteed to be run first. Reviewed-by: Karol Herbst Part-of: --- src/compiler/nir/nir_lower_goto_ifs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/compiler/nir/nir_lower_goto_ifs.c b/src/compiler/nir/nir_lower_goto_ifs.c index 44eaf729ec5..7f62f59212f 100644 --- a/src/compiler/nir/nir_lower_goto_ifs.c +++ b/src/compiler/nir/nir_lower_goto_ifs.c @@ -957,6 +957,12 @@ nir_lower_goto_ifs_impl(nir_function_impl *impl) nir_metadata_require(impl, nir_metadata_dominance); + /* We're going to re-arrange blocks like crazy. This is much easier to do + * if we don't have any phi nodes to fix up. + */ + nir_foreach_block_unstructured(block, impl) + nir_lower_phis_to_regs_block(block); + nir_cf_list cf_list; nir_cf_extract(&cf_list, nir_before_cf_list(&impl->body), nir_after_cf_list(&impl->body)); @@ -997,6 +1003,9 @@ nir_lower_goto_ifs_impl(nir_function_impl *impl) nir_metadata_preserve(impl, nir_metadata_none); + nir_repair_ssa_impl(impl); + nir_lower_regs_to_ssa_impl(impl); + return true; }