i965/fs: Perform CSE on MAD instructions with final arguments switched.
authorMatt Turner <mattst88@gmail.com>
Sun, 26 Oct 2014 17:08:40 +0000 (10:08 -0700)
committerMatt Turner <mattst88@gmail.com>
Thu, 30 Oct 2014 04:35:46 +0000 (21:35 -0700)
Multiplication is commutative.

instructions in affected programs:     48314 -> 47954 (-0.75%)

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_fs_cse.cpp

index 801200118d7386cc392a2923d717d073707b7477..5fdbf4639841cf5ca3e2795c9100a3c446a4a22c 100644 (file)
@@ -128,7 +128,11 @@ operands_match(fs_inst *a, fs_inst *b)
    fs_reg *xs = a->src;
    fs_reg *ys = b->src;
 
-   if (!is_expression_commutative(a->opcode)) {
+   if (a->opcode == BRW_OPCODE_MAD) {
+      return xs[0].equals(ys[0]) &&
+             ((xs[1].equals(ys[1]) && xs[2].equals(ys[2])) ||
+              (xs[2].equals(ys[1]) && xs[1].equals(ys[2])));
+   } else if (!is_expression_commutative(a->opcode)) {
       bool match = true;
       for (int i = 0; i < a->sources; i++) {
          if (!xs[i].equals(ys[i])) {