nir/opt_if: don't mark progress if nothing changes
authorKarol Herbst <kherbst@redhat.com>
Tue, 12 Feb 2019 19:59:35 +0000 (20:59 +0100)
committerKarol Herbst <kherbst@redhat.com>
Tue, 12 Feb 2019 23:21:35 +0000 (00:21 +0100)
if we have something like this:

loop {
   ...
   if x {
      break;
   } else {
      continue;
   }
}

opt_if_loop_last_continue returns true marking progress allthough nothing
changes.

Fixes: 5921a19d4b0c6 "nir: add if opt opt_if_loop_last_continue()"
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_opt_if.c

index 9afb901be14598f7726e9974855ed8549f91bd22..9909faf09a13b5085334e224c9a707ba28f8ec70 100644 (file)
@@ -844,6 +844,13 @@ opt_if_loop_last_continue(nir_loop *loop)
    if (!then_ends_in_continue && !else_ends_in_continue)
       return false;
 
+   /* if the block after the if/else is empty we bail, otherwise we might end
+    * up looping forever
+    */
+   if (&nif->cf_node == nir_cf_node_prev(&last_block->cf_node) &&
+       exec_list_is_empty(&last_block->instr_list))
+      return false;
+
    /* Move the last block of the loop inside the last if-statement */
    nir_cf_list tmp;
    nir_cf_extract(&tmp, nir_after_cf_node(if_node),