nir: Allow casts in nir_deref_instr_get[_const]_offset()

Allow casts in a deref chain so we can calculate an offset from
a base pointer dereference or have pointer type casts in the
middle of the chain (both are pretty common in CL).

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5682>
This commit is contained in:
Boris Brezillon 2020-06-29 15:36:49 +02:00
parent 6a1382399c
commit dd155aef44
1 changed files with 6 additions and 4 deletions

View File

@ -279,8 +279,6 @@ nir_deref_instr_get_const_offset(nir_deref_instr *deref,
nir_deref_path path;
nir_deref_path_init(&path, deref, NULL);
assert(path.path[0]->deref_type == nir_deref_type_var);
unsigned offset = 0;
for (nir_deref_instr **p = &path.path[1]; *p; p++) {
switch ((*p)->deref_type) {
@ -295,6 +293,9 @@ nir_deref_instr_get_const_offset(nir_deref_instr *deref,
(*p)->strct.index);
break;
}
case nir_deref_type_cast:
/* A cast doesn't contribute to the offset */
break;
default:
unreachable("Unsupported deref type");
}
@ -312,8 +313,6 @@ nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
nir_deref_path path;
nir_deref_path_init(&path, deref, NULL);
assert(path.path[0]->deref_type == nir_deref_type_var);
nir_ssa_def *offset = nir_imm_intN_t(b, 0, deref->dest.ssa.bit_size);
for (nir_deref_instr **p = &path.path[1]; *p; p++) {
switch ((*p)->deref_type) {
@ -332,6 +331,9 @@ nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
offset = nir_iadd_imm(b, offset, field_offset);
break;
}
case nir_deref_type_cast:
/* A cast doesn't contribute to the offset */
break;
default:
unreachable("Unsupported deref type");
}