From dd155aef4404994ffc36a63f14fb2ba3f48c0ae5 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Mon, 29 Jun 2020 15:36:49 +0200 Subject: [PATCH] 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: --- src/compiler/nir/nir_deref.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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"); } -- 2.30.2