[Mesa-dev] [PATCH 2/2] i965/fs: Try to avoid generating extra MOVs to do saturates.
Kenneth Graunke
kenneth at whitecape.org
Wed Mar 14 15:51:13 PDT 2012
On 03/13/2012 02:37 PM, Eric Anholt wrote:
> shader-db results:
> Total instructions: 212648 -> 206044
> 614/1246 programs affected (49.3%)
> 178350 -> 171746 instructions in affected programs (3.7% reduction)
> ---
> src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 24 +++++++++++++++++++++---
> 1 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> index eb129ce..e7af75b 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> @@ -172,12 +172,30 @@ fs_visitor::try_emit_saturate(ir_expression *ir)
> if (!sat_val)
> return false;
>
> + fs_inst *pre_inst = (fs_inst *) this->instructions.get_tail();
> +
> sat_val->accept(this);
> fs_reg src = this->result;
>
> - this->result = fs_reg(this, ir->type);
> - fs_inst *inst = emit(BRW_OPCODE_MOV, this->result, src);
> - inst->saturate = true;
> + fs_inst *last_inst = (fs_inst *) this->instructions.get_tail();
> +
> + /* If the last instruction from our accept() didn't generate our
> + * src, generate a saturated MOV
> + */
> + if (last_inst == pre_inst ||
> + last_inst->predicated ||
> + last_inst->force_uncompressed ||
> + last_inst->force_sechalf ||
> + !src.equals(&last_inst->dst) ||
> + last_inst->regs_written() != 1) {
This duplicates a bunch of conditions from try_rewrite_rhs_to_dest. It
also seems like something we're going to want to do more of. Could we
capture some of this in a predicate like "last_inst->writes(src)"?
> + this->result = fs_reg(this, ir->type);
> + fs_inst *inst = emit(BRW_OPCODE_MOV, this->result, src);
> + inst->saturate = true;
> + } else {
> + last_inst->saturate = true;
> + this->result = src;
> + }
> +
>
> return true;
> }
More information about the mesa-dev
mailing list