nir/copy_prop_vars: prefer using entries from equal derefs
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Tue, 29 Jan 2019 20:39:28 +0000 (12:39 -0800)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Fri, 1 Mar 2019 07:55:31 +0000 (23:55 -0800)
When looking up an entry to use, always prefer an equal match, as it
more likely to contain reusable SSA or derefs to propagate.

This will be necessary when adding entries with array derefs of
vectors, because we don't want the vector if the equal entry (an array
deref of that vector) is present.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_opt_copy_prop_vars.c

index b95a455a109517333732180f895fcb65373bb8a3..7fc84083ea697d34181bacf9947d0e545c0f8317 100644 (file)
@@ -302,12 +302,17 @@ lookup_entry_for_deref(struct util_dynarray *copies,
                        nir_deref_instr *deref,
                        nir_deref_compare_result allowed_comparisons)
 {
+   struct copy_entry *entry = NULL;
    util_dynarray_foreach(copies, struct copy_entry, iter) {
-      if (nir_compare_derefs(iter->dst, deref) & allowed_comparisons)
-         return iter;
+      nir_deref_compare_result result = nir_compare_derefs(iter->dst, deref);
+      if (result & allowed_comparisons) {
+         entry = iter;
+         if (result & nir_derefs_equal_bit)
+            break;
+         /* Keep looking in case we have an equal match later in the array. */
+      }
    }
-
-   return NULL;
+   return entry;
 }
 
 static struct copy_entry *