diff --git a/.pick_status.json b/.pick_status.json index 0f1315a8286..6e6d8e1c064 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -44,7 +44,7 @@ "description": "nir: Make is_trivial_deref_cast public", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index c179d3ea23d..58b602e8a8b 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1668,6 +1668,12 @@ typedef struct { nir_def def; } nir_deref_instr; +/** + * Returns true if the cast is trivial, i.e. the source and destination type is + * the same. + */ +bool nir_deref_cast_is_trivial(nir_deref_instr *cast); + /** Returns true if deref might have one of the given modes * * For multi-mode derefs, this returns true if any of the possible modes for diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 2e2ea655a92..f0f5f140130 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -26,9 +26,11 @@ #include "nir.h" #include "nir_builder.h" -static bool -is_trivial_deref_cast(nir_deref_instr *cast) +bool +nir_deref_cast_is_trivial(nir_deref_instr *cast) { + assert(cast->deref_type == nir_deref_type_cast); + nir_deref_instr *parent = nir_src_as_deref(cast->parent); if (!parent) return false; @@ -57,7 +59,7 @@ nir_deref_path_init(nir_deref_path *path, *tail = NULL; for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) { - if (d->deref_type == nir_deref_type_cast && is_trivial_deref_cast(d)) + if (d->deref_type == nir_deref_type_cast && nir_deref_cast_is_trivial(d)) continue; count++; if (count <= max_short_path_len) @@ -80,7 +82,7 @@ nir_deref_path_init(nir_deref_path *path, head = tail = path->path + count; *tail = NULL; for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) { - if (d->deref_type == nir_deref_type_cast && is_trivial_deref_cast(d)) + if (d->deref_type == nir_deref_type_cast && nir_deref_cast_is_trivial(d)) continue; *(--head) = d; } @@ -987,7 +989,7 @@ opt_alu_of_cast(nir_alu_instr *alu) static bool is_trivial_array_deref_cast(nir_deref_instr *cast) { - assert(is_trivial_deref_cast(cast)); + assert(nir_deref_cast_is_trivial(cast)); nir_deref_instr *parent = nir_src_as_deref(cast->parent); @@ -1231,7 +1233,7 @@ opt_deref_cast(nir_builder *b, nir_deref_instr *cast) return true; progress |= opt_remove_cast_cast(cast); - if (!is_trivial_deref_cast(cast)) + if (!nir_deref_cast_is_trivial(cast)) return progress; /* If this deref still contains useful alignment information, we don't want @@ -1283,7 +1285,7 @@ opt_deref_ptr_as_array(nir_builder *b, nir_deref_instr *deref) */ if (parent->deref_type == nir_deref_type_cast && parent->cast.align_mul == 0 && - is_trivial_deref_cast(parent)) + nir_deref_cast_is_trivial(parent)) parent = nir_deref_instr_parent(parent); nir_def_rewrite_uses(&deref->def, &parent->def);