From 78f7c9edeb21ec4e7a4f96aa12b51cecc40e9688 Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Wed, 3 Jun 2015 19:33:44 +0300 Subject: [PATCH] i965/fs: Create and emit instructions in one step in opt_peephole_sel. This simplifies opt_peephole_sel() slightly by emitting the SEL instructions immediately after they are created, what makes the sel_inst and mov_imm_inst arrays unnecessary and will make it possible to get rid of the explicit inserts when the pass is migrated to the IR builder. Reviewed-by: Matt Turner --- .../drivers/dri/i965/brw_fs_sel_peephole.cpp | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp b/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp index 52aa5590c2e..635c91b9d46 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp @@ -153,9 +153,6 @@ fs_visitor::opt_peephole_sel() if (movs == 0) continue; - fs_inst *sel_inst[MAX_MOVS] = { NULL }; - fs_inst *mov_imm_inst[MAX_MOVS] = { NULL }; - enum brw_predicate predicate; bool predicate_inverse; if (devinfo->gen == 6 && if_inst->conditional_mod) { @@ -188,25 +185,6 @@ fs_visitor::opt_peephole_sel() movs = i; break; } - - if (then_mov[i]->src[0].equals(else_mov[i]->src[0])) { - sel_inst[i] = MOV(then_mov[i]->dst, then_mov[i]->src[0]); - } else { - /* Only the last source register can be a constant, so if the MOV - * in the "then" clause uses a constant, we need to put it in a - * temporary. - */ - fs_reg src0(then_mov[i]->src[0]); - if (src0.file == IMM) { - src0 = vgrf(glsl_type::float_type); - src0.type = then_mov[i]->src[0].type; - mov_imm_inst[i] = MOV(src0, then_mov[i]->src[0]); - } - - sel_inst[i] = SEL(then_mov[i]->dst, src0, else_mov[i]->src[0]); - sel_inst[i]->predicate = predicate; - sel_inst[i]->predicate_inverse = predicate_inverse; - } } if (movs == 0) @@ -220,9 +198,27 @@ fs_visitor::opt_peephole_sel() } for (int i = 0; i < movs; i++) { - if (mov_imm_inst[i]) - if_inst->insert_before(block, mov_imm_inst[i]); - if_inst->insert_before(block, sel_inst[i]); + if (then_mov[i]->src[0].equals(else_mov[i]->src[0])) { + fs_inst *inst = MOV(then_mov[i]->dst, then_mov[i]->src[0]); + if_inst->insert_before(block, inst); + } else { + /* Only the last source register can be a constant, so if the MOV + * in the "then" clause uses a constant, we need to put it in a + * temporary. + */ + fs_reg src0(then_mov[i]->src[0]); + if (src0.file == IMM) { + src0 = vgrf(glsl_type::float_type); + src0.type = then_mov[i]->src[0].type; + fs_inst *inst = MOV(src0, then_mov[i]->src[0]); + if_inst->insert_before(block, inst); + } + + fs_inst *inst = SEL(then_mov[i]->dst, src0, else_mov[i]->src[0]); + inst->predicate = predicate; + inst->predicate_inverse = predicate_inverse; + if_inst->insert_before(block, inst); + } then_mov[i]->remove(then_block); else_mov[i]->remove(else_block);