From b4515759897e7efa85bc77940948967e6f21e28a Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Thu, 15 Aug 2024 08:46:36 +0200 Subject: [PATCH] nir/opt_vectorize: prepare for multiple try_combine functions Dispatch to different functions inside instr_try_combine. To prepare for upcoming support for phi nodes. Signed-off-by: Job Noorman Reviewed-by: Connor Abbott Part-of: --- src/compiler/nir/nir_opt_vectorize.c | 37 +++++++++++++++++----------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/compiler/nir/nir_opt_vectorize.c b/src/compiler/nir/nir_opt_vectorize.c index 7c593a26759..e686dd12a4b 100644 --- a/src/compiler/nir/nir_opt_vectorize.c +++ b/src/compiler/nir/nir_opt_vectorize.c @@ -230,29 +230,19 @@ rewrite_uses(nir_builder *b, struct set *instr_set, nir_def *def1, nir_instr_remove(def2->parent_instr); } -/* - * Tries to combine two instructions whose sources are different components of - * the same instructions into one vectorized instruction. Note that instr1 - * should dominate instr2. - */ static nir_instr * -instr_try_combine(struct set *instr_set, nir_instr *instr1, nir_instr *instr2) +instr_try_combine_alu(struct set *instr_set, nir_alu_instr *alu1, nir_alu_instr *alu2) { - assert(instr1->type == nir_instr_type_alu); - assert(instr2->type == nir_instr_type_alu); - nir_alu_instr *alu1 = nir_instr_as_alu(instr1); - nir_alu_instr *alu2 = nir_instr_as_alu(instr2); - assert(alu1->def.bit_size == alu2->def.bit_size); unsigned alu1_components = alu1->def.num_components; unsigned alu2_components = alu2->def.num_components; unsigned total_components = alu1_components + alu2_components; - assert(instr1->pass_flags == instr2->pass_flags); - if (total_components > instr1->pass_flags) + assert(alu1->instr.pass_flags == alu2->instr.pass_flags); + if (total_components > alu1->instr.pass_flags) return NULL; - nir_builder b = nir_builder_at(nir_after_instr(instr1)); + nir_builder b = nir_builder_at(nir_after_instr(&alu1->instr)); nir_alu_instr *new_alu = nir_alu_instr_create(b.shader, alu1->op); nir_def_init(&new_alu->instr, &new_alu->def, total_components, @@ -307,6 +297,25 @@ instr_try_combine(struct set *instr_set, nir_instr *instr1, nir_instr *instr2) return &new_alu->instr; } +/* + * Tries to combine two instructions whose sources are different components of + * the same instructions into one vectorized instruction. Note that instr1 + * should dominate instr2. + */ +static nir_instr * +instr_try_combine(struct set *instr_set, nir_instr *instr1, nir_instr *instr2) +{ + switch (instr1->type) { + case nir_instr_type_alu: + assert(instr2->type == nir_instr_type_alu); + return instr_try_combine_alu(instr_set, nir_instr_as_alu(instr1), + nir_instr_as_alu(instr2)); + + default: + unreachable("Unsupported instruction type"); + } +} + static struct set * vec_instr_set_create(void) {