Mesa (master): i965: Consider SEL.{GE, L} to be commutative operations.

Matt Turner mattst88 at kemper.freedesktop.org
Thu Jan 8 23:51:54 UTC 2015


Module: Mesa
Branch: master
Commit: 3d8188d4f898afcf4f181de29e12c5b218bbd393
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3d8188d4f898afcf4f181de29e12c5b218bbd393

Author: Matt Turner <mattst88 at gmail.com>
Date:   Sat Dec 20 12:21:46 2014 -0800

i965: Consider SEL.{GE,L} to be commutative operations.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/drivers/dri/i965/brw_fs_cse.cpp   |   15 +++++++++++----
 src/mesa/drivers/dri/i965/brw_vec4_cse.cpp |   22 ++++++++++++++++------
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
index 38fae17..f87601c 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
@@ -109,22 +109,29 @@ is_expression(const fs_inst *const inst)
 }
 
 static bool
-is_expression_commutative(enum opcode op)
+is_expression_commutative(const fs_inst *inst)
 {
-   switch (op) {
+   switch (inst->opcode) {
    case BRW_OPCODE_AND:
    case BRW_OPCODE_OR:
    case BRW_OPCODE_XOR:
    case BRW_OPCODE_ADD:
    case BRW_OPCODE_MUL:
       return true;
+   case BRW_OPCODE_SEL:
+      /* MIN and MAX are commutative. */
+      if (inst->conditional_mod == BRW_CONDITIONAL_GE ||
+          inst->conditional_mod == BRW_CONDITIONAL_L) {
+         return true;
+      }
+      /* fallthrough */
    default:
       return false;
    }
 }
 
 static bool
-operands_match(fs_inst *a, fs_inst *b)
+operands_match(const fs_inst *a, const fs_inst *b)
 {
    fs_reg *xs = a->src;
    fs_reg *ys = b->src;
@@ -133,7 +140,7 @@ operands_match(fs_inst *a, fs_inst *b)
       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)) {
+   } else if (!is_expression_commutative(a)) {
       bool match = true;
       for (int i = 0; i < a->sources; i++) {
          if (!xs[i].equals(ys[i])) {
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp b/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp
index 37c930c..30a4098 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp
@@ -89,28 +89,38 @@ is_expression(const vec4_instruction *const inst)
 }
 
 static bool
-is_expression_commutative(enum opcode op)
+is_expression_commutative(const vec4_instruction *inst)
 {
-   switch (op) {
+   switch (inst->opcode) {
    case BRW_OPCODE_AND:
    case BRW_OPCODE_OR:
    case BRW_OPCODE_XOR:
    case BRW_OPCODE_ADD:
    case BRW_OPCODE_MUL:
       return true;
+   case BRW_OPCODE_SEL:
+      /* MIN and MAX are commutative. */
+      if (inst->conditional_mod == BRW_CONDITIONAL_GE ||
+          inst->conditional_mod == BRW_CONDITIONAL_L) {
+         return true;
+      }
+      /* fallthrough */
    default:
       return false;
    }
 }
 
 static bool
-operands_match(enum opcode op, src_reg *xs, src_reg *ys)
+operands_match(const vec4_instruction *a, const vec4_instruction *b)
 {
-   if (op == BRW_OPCODE_MAD) {
+   const src_reg *xs = a->src;
+   const src_reg *ys = b->src;
+
+   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(op)) {
+   } else if (!is_expression_commutative(a)) {
       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])) ||
@@ -126,7 +136,7 @@ instructions_match(vec4_instruction *a, vec4_instruction *b)
           a->conditional_mod == b->conditional_mod &&
           a->dst.type == b->dst.type &&
           a->dst.writemask == b->dst.writemask &&
-          operands_match(a->opcode, a->src, b->src);
+          operands_match(a, b);
 }
 
 bool




More information about the mesa-commit mailing list