nir: Make is_trivial_deref_cast public

Cc: mesa-stable

Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27197>
(cherry picked from commit 6c845ed548)
This commit is contained in:
Friedrich Vock 2024-01-22 18:06:44 +01:00 committed by Eric Engestrom
parent d2094c1e1b
commit 466ae8c313
3 changed files with 16 additions and 8 deletions

View file

@ -44,7 +44,7 @@
"description": "nir: Make is_trivial_deref_cast public", "description": "nir: Make is_trivial_deref_cast public",
"nominated": true, "nominated": true,
"nomination_type": 0, "nomination_type": 0,
"resolution": 0, "resolution": 1,
"main_sha": null, "main_sha": null,
"because_sha": null, "because_sha": null,
"notes": null "notes": null

View file

@ -1668,6 +1668,12 @@ typedef struct {
nir_def def; nir_def def;
} nir_deref_instr; } 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 /** 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 * For multi-mode derefs, this returns true if any of the possible modes for

View file

@ -26,9 +26,11 @@
#include "nir.h" #include "nir.h"
#include "nir_builder.h" #include "nir_builder.h"
static bool bool
is_trivial_deref_cast(nir_deref_instr *cast) 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); nir_deref_instr *parent = nir_src_as_deref(cast->parent);
if (!parent) if (!parent)
return false; return false;
@ -57,7 +59,7 @@ nir_deref_path_init(nir_deref_path *path,
*tail = NULL; *tail = NULL;
for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) { 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; continue;
count++; count++;
if (count <= max_short_path_len) if (count <= max_short_path_len)
@ -80,7 +82,7 @@ nir_deref_path_init(nir_deref_path *path,
head = tail = path->path + count; head = tail = path->path + count;
*tail = NULL; *tail = NULL;
for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) { 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; continue;
*(--head) = d; *(--head) = d;
} }
@ -987,7 +989,7 @@ opt_alu_of_cast(nir_alu_instr *alu)
static bool static bool
is_trivial_array_deref_cast(nir_deref_instr *cast) 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); 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; return true;
progress |= opt_remove_cast_cast(cast); progress |= opt_remove_cast_cast(cast);
if (!is_trivial_deref_cast(cast)) if (!nir_deref_cast_is_trivial(cast))
return progress; return progress;
/* If this deref still contains useful alignment information, we don't want /* 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 && if (parent->deref_type == nir_deref_type_cast &&
parent->cast.align_mul == 0 && parent->cast.align_mul == 0 &&
is_trivial_deref_cast(parent)) nir_deref_cast_is_trivial(parent))
parent = nir_deref_instr_parent(parent); parent = nir_deref_instr_parent(parent);
nir_def_rewrite_uses(&deref->def, nir_def_rewrite_uses(&deref->def,
&parent->def); &parent->def);