- if (progress && !state->loop)
- predicate_following(&if_stmt->cf_node, state);
+ if (progress && !state->loop) {
+ if (state->has_predicated_return) {
+ predicate_following(&if_stmt->cf_node, state);
+ } else {
+ /* If there are no nested returns we can just add the instructions to
+ * the end of the branch that doesn't have the return.
+ */
+ nir_cf_list list;
+ nir_cf_extract(&list, nir_after_cf_node(&if_stmt->cf_node),
+ nir_after_cf_list(state->cf_list));
+
+ if (then_progress && else_progress) {
+ /* Both branches return so delete instructions following the if */
+ nir_cf_delete(&list);
+ } else if (then_progress) {
+ nir_cf_reinsert(&list, nir_after_cf_list(&if_stmt->else_list));
+ } else {
+ nir_cf_reinsert(&list, nir_after_cf_list(&if_stmt->then_list));
+ }
+ }
+ }
+
+ state->has_predicated_return = progress || has_predicated_return;