summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Ekstrand <jason@jlekstrand.net>2019-08-30 14:16:07 -0500
committerDylan Baker <dylan@pnwbakers.com>2019-09-09 09:14:43 -0700
commit2012c4a75cb5ce87a17e0cc6238d6363a2ef6c30 (patch)
tree3ffd6cd5b1d9d03a87890ccadedb63e897e63908
parent3f56fa8fe9aa3df31b5712a89579168e07b314c7 (diff)
nir/repair_ssa: Insert deref casts when needed
Cc: mesa-stable@lists.freedesktop.org Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> (cherry picked from commit 1005272a2b7c744b6ac4d846566359a8ff1b6295)
-rw-r--r--src/compiler/nir/nir_repair_ssa.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/compiler/nir/nir_repair_ssa.c b/src/compiler/nir/nir_repair_ssa.c
index b6ec1038843..757afff490d 100644
--- a/src/compiler/nir/nir_repair_ssa.c
+++ b/src/compiler/nir/nir_repair_ssa.c
@@ -105,8 +105,35 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
nir_block *src_block = get_src_block(src);
if (nir_block_is_unreachable(src_block) ||
!nir_block_dominates(def->parent_instr->block, src_block)) {
- nir_instr_rewrite_src(src->parent_instr, src, nir_src_for_ssa(
- nir_phi_builder_value_get_block_def(val, src_block)));
+ nir_ssa_def *block_def =
+ nir_phi_builder_value_get_block_def(val, src_block);
+
+ /* If def was a deref and the use we're looking at is a deref that
+ * isn't a cast, we need to wrap it in a cast so we don't loose any
+ * deref information.
+ */
+ if (def->parent_instr->type == nir_instr_type_deref &&
+ src->parent_instr->type == nir_instr_type_deref &&
+ nir_instr_as_deref(src->parent_instr)->deref_type != nir_deref_type_cast) {
+ nir_deref_instr *cast =
+ nir_deref_instr_create(state->impl->function->shader,
+ nir_deref_type_cast);
+
+ nir_deref_instr *deref = nir_instr_as_deref(def->parent_instr);
+ cast->mode = deref->mode;
+ cast->type = deref->type;
+ cast->parent = nir_src_for_ssa(block_def);
+ cast->cast.ptr_stride = nir_deref_instr_ptr_as_array_stride(deref);
+
+ nir_ssa_dest_init(&cast->instr, &cast->dest,
+ def->num_components, def->bit_size, NULL);
+ nir_instr_insert(nir_before_instr(src->parent_instr),
+ &cast->instr);
+ block_def = &cast->dest.ssa;
+ }
+
+ nir_instr_rewrite_src(src->parent_instr, src,
+ nir_src_for_ssa(block_def));
}
}