From 3ad2d85995eccc5b79732f93a2ced4800275b19b Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 5 Nov 2020 23:16:19 -0600 Subject: [PATCH] intel/nir: Refactor lower_bit_size_callback We want to use it for more than just ALU. Reviewed-by: Kenneth Graunke Part-of: --- src/intel/compiler/brw_nir.c | 64 ++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c index 61c1ef98338..71771a5fc58 100644 --- a/src/intel/compiler/brw_nir.c +++ b/src/intel/compiler/brw_nir.c @@ -635,37 +635,43 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler, static unsigned lower_bit_size_callback(const nir_instr *instr, UNUSED void *data) { - if (instr->type != nir_instr_type_alu) - return 0; - - nir_alu_instr *alu = nir_instr_as_alu(instr); - assert(alu->dest.dest.is_ssa); - if (alu->dest.dest.ssa.bit_size >= 32) - return 0; - const struct brw_compiler *compiler = (const struct brw_compiler *) data; + const struct gen_device_info *devinfo = compiler->devinfo; + + switch (instr->type) { + case nir_instr_type_alu: { + nir_alu_instr *alu = nir_instr_as_alu(instr); + assert(alu->dest.dest.is_ssa); + if (alu->dest.dest.ssa.bit_size >= 32) + return 0; + + switch (alu->op) { + case nir_op_idiv: + case nir_op_imod: + case nir_op_irem: + case nir_op_udiv: + case nir_op_umod: + case nir_op_fceil: + case nir_op_ffloor: + case nir_op_ffract: + case nir_op_fround_even: + case nir_op_ftrunc: + return 32; + case nir_op_frcp: + case nir_op_frsq: + case nir_op_fsqrt: + case nir_op_fpow: + case nir_op_fexp2: + case nir_op_flog2: + case nir_op_fsin: + case nir_op_fcos: + return devinfo->gen < 9 ? 32 : 0; + default: + return 0; + } + break; + } - switch (alu->op) { - case nir_op_idiv: - case nir_op_imod: - case nir_op_irem: - case nir_op_udiv: - case nir_op_umod: - case nir_op_fceil: - case nir_op_ffloor: - case nir_op_ffract: - case nir_op_fround_even: - case nir_op_ftrunc: - return 32; - case nir_op_frcp: - case nir_op_frsq: - case nir_op_fsqrt: - case nir_op_fpow: - case nir_op_fexp2: - case nir_op_flog2: - case nir_op_fsin: - case nir_op_fcos: - return compiler->devinfo->gen < 9 ? 32 : 0; default: return 0; }