[Mesa-dev] [RFC 8/9] i965/fs: Allow immediates in MAD and LRP instructions.

Matt Turner mattst88 at gmail.com
Fri Oct 31 18:27:52 PDT 2014


And then the opt_combine_constants() pass will pull them out into
registers.
---
 .../drivers/dri/i965/brw_fs_combine_constants.cpp  | 22 +++++++++++++++++++---
 .../drivers/dri/i965/brw_fs_copy_propagation.cpp   |  6 ++++++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_combine_constants.cpp b/src/mesa/drivers/dri/i965/brw_fs_combine_constants.cpp
index eef6bb8..67c1663 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_combine_constants.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_combine_constants.cpp
@@ -60,6 +60,18 @@ could_coissue(const fs_inst *inst)
    }
 }
 
+static bool
+must_promote_imm(const fs_inst *inst)
+{
+   switch (inst->opcode) {
+   case BRW_OPCODE_MAD:
+   case BRW_OPCODE_LRP:
+      return true;
+   default:
+      return false;
+   }
+}
+
 struct imm {
    bblock_t *block;
    float val;
@@ -68,6 +80,7 @@ struct imm {
    uint16_t reg;
 
    uint16_t uses_by_coissue;
+   bool must_promote;
 };
 
 struct table {
@@ -118,10 +131,11 @@ fs_visitor::opt_combine_constants()
    cfg->calculate_idom();
 
    /* Make a pass through all instructions and count the number of times each
-    * constant is used by coissueable instructions.
+    * constant is used by coissueable instructions or instructions that cannot
+    * take immediate arguments.
     */
    foreach_block_and_inst(block, fs_inst, inst, cfg) {
-      if (!could_coissue(inst))
+      if (!could_coissue(inst) && !must_promote_imm(inst))
          continue;
 
       for (int i = 0; i < inst->sources; i++) {
@@ -134,11 +148,13 @@ fs_visitor::opt_combine_constants()
          if (imm) {
             imm->block = cfg_t::intersect(block, imm->block);
             imm->uses_by_coissue += could_coissue(inst);
+            imm->must_promote = imm->must_promote || must_promote_imm(inst);
          } else {
             imm = new_imm(&table, const_ctx);
             imm->block = block;
             imm->val = val;
             imm->uses_by_coissue = could_coissue(inst);
+            imm->must_promote = must_promote_imm(inst);
          }
       }
    }
@@ -149,7 +165,7 @@ fs_visitor::opt_combine_constants()
    for (int i = 0; i < table.len;) {
       struct imm *imm = &table.imm[i];
 
-      if (imm->uses_by_coissue < 4) {
+      if (!imm->must_promote && imm->uses_by_coissue < 4) {
          table.imm[i] = table.imm[table.len - 1];
          table.len--;
          continue;
diff --git a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
index e1989cb..0ee95cd 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
@@ -563,6 +563,12 @@ fs_visitor::try_constant_propagate(fs_inst *inst, acp_entry *entry)
          progress = true;
          break;
 
+      case BRW_OPCODE_MAD:
+      case BRW_OPCODE_LRP:
+         inst->src[i] = val;
+         progress = true;
+         break;
+
       default:
          break;
       }
-- 
2.0.4



More information about the mesa-dev mailing list