nir: Lower returns correctly inside nested loops
authorArcady Goldmints-Orlov <agoldmints@igalia.com>
Thu, 16 Apr 2020 21:28:12 +0000 (16:28 -0500)
committerMarge Bot <eric+marge@anholt.net>
Sun, 19 Apr 2020 02:54:08 +0000 (02:54 +0000)
Inside nested flow control, nir_lower_returns inserts predicated breaks
in the outer block. However, it would omit doing this if the remainder
of the outer block (after the inner block) was empty. This is not
correct in the case of loops, as execution just wraps back around to the
start of the loop, so this change doesn't skip the predication inside
loops.

Fixes: 79dec93ead6e (nir: Add return lowering pass)
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2724
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4603>

src/compiler/nir/nir_lower_returns.c

index e166a7cc32a54dea712756e6940ba0acd0644f44..ecbbf43da3bc9d409d72ef4a29664778346ca4a5 100644 (file)
@@ -50,7 +50,7 @@ predicate_following(nir_cf_node *node, struct lower_returns_state *state)
    nir_builder *b = &state->builder;
    b->cursor = nir_after_cf_node_and_phis(node);
 
-   if (nir_cursors_equal(b->cursor, nir_after_cf_list(state->cf_list)))
+   if (!state->loop && nir_cursors_equal(b->cursor, nir_after_cf_list(state->cf_list)))
       return; /* Nothing to predicate */
 
    assert(state->return_flag);