From: Boris Brezillon Date: Mon, 29 Jun 2020 13:36:49 +0000 (+0200) Subject: nir: Allow casts in nir_deref_instr_get[_const]_offset() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dd155aef4404994ffc36a63f14fb2ba3f48c0ae5;p=mesa.git 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 Reviewed-by: Jason Ekstrand Part-of: --- diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 83c401282c5..dca76210f8f 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -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"); }