summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2018-06-04 16:26:46 +1000
committerDylan Baker <[email protected]>2018-07-03 10:26:16 -0700
commit81af1a0ae264378408232dc1e54b00a7dff3529b (patch)
treef3d60a13c1052cdb116e824f337bd600b723113e
parent4cd70c4cdf61d3fa75c907c01e375ff0113a64bf (diff)
nir: fix selection of loop terminator when two or more have the same limit
We need to add loop terminators to the list in the order we come across them otherwise if two or more have the same exit condition we will select that last one rather than the first one even though its unreachable. This fix is for simple unrolls where we only have a single exit point. When unrolling these type of loops the unreachable terminators and their unreachable branch are removed prior to unrolling. Because of the logic change we also switch some list access in the complex unrolling logic to avoid breakage. Fixes: 6772a17acc8e ("nir: Add a loop analysis pass") Reviewed-by: Jason Ekstrand <[email protected]> (cherry picked from commit 463f849097193ad20e7622ddd740fd15b96f4277)
-rw-r--r--src/compiler/nir/nir_loop_analyze.c4
-rw-r--r--src/compiler/nir/nir_opt_loop_unroll.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c
index 84da035052d..aa6877f3af5 100644
--- a/src/compiler/nir/nir_loop_analyze.c
+++ b/src/compiler/nir/nir_loop_analyze.c
@@ -341,8 +341,8 @@ find_loop_terminators(loop_info_state *state)
nir_loop_terminator *terminator =
rzalloc(state->loop->info, nir_loop_terminator);
- list_add(&terminator->loop_terminator_link,
- &state->loop->info->loop_terminator_list);
+ list_addtail(&terminator->loop_terminator_link,
+ &state->loop->info->loop_terminator_list);
terminator->nif = nif;
terminator->break_block = break_blk;
diff --git a/src/compiler/nir/nir_opt_loop_unroll.c b/src/compiler/nir/nir_opt_loop_unroll.c
index ff27c06cc01..b8efbb5ee93 100644
--- a/src/compiler/nir/nir_opt_loop_unroll.c
+++ b/src/compiler/nir/nir_opt_loop_unroll.c
@@ -530,14 +530,14 @@ process_loops(nir_shader *sh, nir_cf_node *cf_node, bool *innermost_loop)
if (num_lt == 2) {
bool limiting_term_second = true;
nir_loop_terminator *terminator =
- list_last_entry(&loop->info->loop_terminator_list,
+ list_first_entry(&loop->info->loop_terminator_list,
nir_loop_terminator, loop_terminator_link);
if (terminator->nif == loop->info->limiting_terminator->nif) {
limiting_term_second = false;
terminator =
- list_first_entry(&loop->info->loop_terminator_list,
+ list_last_entry(&loop->info->loop_terminator_list,
nir_loop_terminator, loop_terminator_link);
}