[Mesa-dev] [PATCH 2/7] i965/fs: Match commutative expressions with reversed arguments.

Eric Anholt eric at anholt.net
Tue Oct 22 23:07:38 CEST 2013


Matt Turner <mattst88 at gmail.com> writes:

> total instructions in shared programs: 1645011 -> 1644938 (-0.00%)
> instructions in affected programs:     17543 -> 17470 (-0.42%)
> ---
>  src/mesa/drivers/dri/i965/brw_fs_cse.cpp | 26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
> index ab3e561..0afc5f6 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
> @@ -77,9 +77,29 @@ is_expression(const fs_inst *const inst)
>  }
>  
>  static bool
> -operands_match(fs_reg *xs, fs_reg *ys)
> +is_expression_commutative(enum opcode op)
>  {
> -   return xs[0].equals(ys[0]) && xs[1].equals(ys[1]) && xs[2].equals(ys[2]);
> +   switch (op) {
> +   case BRW_OPCODE_AND:
> +   case BRW_OPCODE_OR:
> +   case BRW_OPCODE_XOR:
> +   case BRW_OPCODE_ADD:
> +   case BRW_OPCODE_MUL:
> +      return true;
> +   default:
> +      return false;
> +   }
> +}
> +
> +static bool
> +operands_match(enum opcode op, fs_reg *xs, fs_reg *ys)
> +{
> +   if (!is_expression_commutative(op)) {
> +      return xs[0].equals(ys[0]) && xs[1].equals(ys[1]) && xs[2].equals(ys[2]);
> +   } else {
> +      return (xs[0].equals(ys[0]) && xs[1].equals(ys[1])) ||
> +             (xs[1].equals(ys[0]) && xs[0].equals(ys[1]));
> +   }
>  }

This is_expression_commutative() path assumes that x and y have the same
type (since gen6+ only look at src0 type for operands handling), but I
believe we have no cases where we intentionally mismatch types in our
sources in any way that matters (some pull constant math I think might
mismatch between D and UD, but it doesn't care since it will never reach
maxint we hope).

The first 2 patches are:

Reviewed-by: Eric Anholt <eric at anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131022/f1bd5f6e/attachment.pgp>


More information about the mesa-dev mailing list