[Mesa-dev] [PATCH 4/8] i965/fs: Optimize a * 1.0 -> a.

Ian Romanick idr at freedesktop.org
Mon Jul 25 18:47:12 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/25/2011 03:39 PM, Eric Anholt wrote:
> This appears in our instruction stream as a result of the
> brw_vs_constval.c handling.
> ---
>  src/mesa/drivers/dri/i965/brw_fs.cpp |   43 ++++++++++++++++++++++++++++++++++
>  src/mesa/drivers/dri/i965/brw_fs.h   |    1 +
>  2 files changed, 44 insertions(+), 0 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
> index 6d91668..d072e22 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
> @@ -1069,6 +1069,7 @@ fs_visitor::propagate_constants()
>  	       if (inst->src[0].imm.f != 0.0f) {
>  		  scan_inst->opcode = BRW_OPCODE_MOV;
>  		  scan_inst->src[0] = inst->src[0];
> +		  scan_inst->src[0].imm.f = 1.0f / scan_inst->src[0].imm.f;
>  		  progress = true;
>  	       }
>  	       break;
> @@ -1089,6 +1090,47 @@ fs_visitor::propagate_constants()
>  
>     return progress;
>  }
> +
> +
> +/**
> + * Attempts to move immediate constants into the immediate
> + * constant slot of following instructions.
> + *
> + * Immediate constants are a bit tricky -- they have to be in the last
> + * operand slot, you can't do abs/negate on them,
> + */
> +
> +bool
> +fs_visitor::opt_algebraic()
> +{
> +   bool progress = false;
> +
> +   calculate_live_intervals();
> +
> +   foreach_iter(exec_list_iterator, iter, this->instructions) {
> +      fs_inst *inst = (fs_inst *)iter.get();

    foreach_list(node, this->instructions) {
        fs_inst *inst = (fs_inst *) node;

We added these macros a long time ago because the iterators turned out
to be such fail.

> +
> +      switch (inst->opcode) {
> +      case BRW_OPCODE_MUL:
> +	 if (inst->src[1].file != IMM)
> +	    continue;
> +
> +	 /* a * 1.0 = a */
> +	 if (inst->src[1].type == BRW_REGISTER_TYPE_F &&
> +	     inst->src[1].imm.f == 1.0) {
> +	    inst->opcode = BRW_OPCODE_MOV;
> +	    inst->src[1] = reg_undef;
> +	    progress = true;
> +	    break;
> +	 }
> +
> +	 break;
> +      }
> +   }
> +
> +   return progress;
> +}
> +
>  /**
>   * Must be called after calculate_live_intervales() to remove unused
>   * writes to registers -- register allocation will fail otherwise
> @@ -1576,6 +1618,7 @@ fs_visitor::run()
>  	 progress = remove_duplicate_mrf_writes() || progress;
>  
>  	 progress = propagate_constants() || progress;
> +	 progress = opt_algebraic() || progress;
>  	 progress = register_coalesce() || progress;
>  	 progress = compute_to_mrf() || progress;
>  	 progress = dead_code_eliminate() || progress;
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
> index 2bf850e..89d6cda 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.h
> +++ b/src/mesa/drivers/dri/i965/brw_fs.h
> @@ -485,6 +485,7 @@ public:
>     void setup_pull_constants();
>     void calculate_live_intervals();
>     bool propagate_constants();
> +   bool opt_algebraic();
>     bool register_coalesce();
>     bool compute_to_mrf();
>     bool dead_code_eliminate();
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk4uHKAACgkQX1gOwKyEAw/pOACglSeXrx0tCrrsl6rlEtNX5z6p
vn4AoKCBsnI7sl1RwqE30VoclM/Zs/D/
=eeEb
-----END PGP SIGNATURE-----


More information about the mesa-dev mailing list