summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-12-15 14:06:58 -0800
committerJason Ekstrand <[email protected]>2015-01-15 07:20:22 -0800
commitbc0735857f1f36eede7e8e5382f8e9bbc496fecb (patch)
treef326d0b1d361eba320d5735e5c558aaecd68ce85 /src/glsl
parentdfb3abbaecfbe30b8858a5428c604f9d90f65505 (diff)
nir/lower_variables: Use a real dominance DFS for variable renaming
Previously, we were just iterating over the program "in order" which kind-of approximates a DFS, but not really. In particular, we got the following case wrong: loop { a = 3; if (foo) { a = 5; } else { break; } use(a); } where use(a) would get 3 instead of 5 because of premature popping of the SSA def stack. Now, since we do an actaul DFS, we should evaluate use(a) immediately after a = 5 and we should be ok. Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/nir/nir_lower_variables.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/glsl/nir/nir_lower_variables.c b/src/glsl/nir/nir_lower_variables.c
index 4fa421a4d65..95ced8254b4 100644
--- a/src/glsl/nir/nir_lower_variables.c
+++ b/src/glsl/nir/nir_lower_variables.c
@@ -725,10 +725,8 @@ add_phi_sources(nir_block *block, nir_block *pred,
}
static bool
-lower_deref_to_ssa_block(nir_block *block, void *void_state)
+rename_variables_block(nir_block *block, struct lower_variables_state *state)
{
- struct lower_variables_state *state = void_state;
-
nir_foreach_instr_safe(block, instr) {
if (instr->type == nir_instr_type_phi) {
nir_phi_instr *phi = nir_instr_as_phi(instr);
@@ -856,6 +854,9 @@ lower_deref_to_ssa_block(nir_block *block, void *void_state)
if (block->successors[1])
add_phi_sources(block->successors[1], block, state);
+ for (unsigned i = 0; i < block->num_dom_children; ++i)
+ rename_variables_block(block->dom_children[i], state);
+
return true;
}
@@ -996,7 +997,7 @@ nir_lower_variables_impl(nir_function_impl *impl)
nir_metadata_require(impl, nir_metadata_dominance);
insert_phi_nodes(&state);
- nir_foreach_block(impl, lower_deref_to_ssa_block, &state);
+ rename_variables_block(impl->start_block, &state);
nir_metadata_preserve(impl, nir_metadata_block_index |
nir_metadata_dominance);