i915: Remove most of the code under gen >= 4 checks.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs_cse.cpp
index e0f824c5e3e6a3d8379caa8bde075c94f0eef3d2..9b60d9be41b0eef160d8755ec8b5053e520b265f 100644 (file)
@@ -68,6 +68,8 @@ is_expression(const fs_inst *const inst)
    case BRW_OPCODE_MAD:
    case BRW_OPCODE_LRP:
    case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD:
+   case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7:
+   case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD:
    case FS_OPCODE_CINTERP:
    case FS_OPCODE_LINTERP:
       return true;
@@ -89,13 +91,13 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
 
    void *mem_ctx = ralloc_context(this->mem_ctx);
 
+   int ip = block->start_ip;
    for (fs_inst *inst = (fs_inst *)block->start;
        inst != block->end->next;
        inst = (fs_inst *) inst->next) {
 
       /* Skip some cases. */
-      if (is_expression(inst) && !inst->predicate && inst->mlen == 0 &&
-          !inst->force_uncompressed && !inst->force_sechalf &&
+      if (is_expression(inst) && !inst->is_partial_write() &&
           !inst->conditional_mod)
       {
         bool found = false;
@@ -128,21 +130,41 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
             */
            bool no_existing_temp = entry->tmp.file == BAD_FILE;
            if (no_existing_temp) {
-              entry->tmp = fs_reg(this, glsl_type::float_type);
-              entry->tmp.type = inst->dst.type;
-
-              fs_inst *copy = new(ralloc_parent(inst))
-                 fs_inst(BRW_OPCODE_MOV, entry->generator->dst, entry->tmp);
-              entry->generator->insert_after(copy);
-              entry->generator->dst = entry->tmp;
+               int written = entry->generator->regs_written;
+
+               fs_reg orig_dst = entry->generator->dst;
+               fs_reg tmp = fs_reg(GRF, virtual_grf_alloc(written),
+                                   orig_dst.type);
+               entry->tmp = tmp;
+               entry->generator->dst = tmp;
+
+               for (int i = 0; i < written; i++) {
+                  fs_inst *copy = MOV(orig_dst, tmp);
+                  copy->force_writemask_all =
+                     entry->generator->force_writemask_all;
+                  entry->generator->insert_after(copy);
+
+                  orig_dst.reg_offset++;
+                  tmp.reg_offset++;
+               }
            }
 
            /* dest <- temp */
+            int written = inst->regs_written;
+            assert(written == entry->generator->regs_written);
             assert(inst->dst.type == entry->tmp.type);
-           fs_inst *copy = new(ralloc_parent(inst))
-              fs_inst(BRW_OPCODE_MOV, inst->dst, entry->tmp);
-            copy->force_writemask_all = inst->force_writemask_all;
-           inst->replace_with(copy);
+            fs_reg dst = inst->dst;
+            fs_reg tmp = entry->tmp;
+            fs_inst *copy = NULL;
+            for (int i = 0; i < written; i++) {
+               copy = MOV(dst, tmp);
+               copy->force_writemask_all = inst->force_writemask_all;
+               inst->insert_before(copy);
+
+               dst.reg_offset++;
+               tmp.reg_offset++;
+            }
+            inst->remove();
 
            /* Appending an instruction may have changed our bblock end. */
            if (inst == block->end) {
@@ -154,18 +176,33 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
         }
       }
 
-      /* Kill all AEB entries that use the destination. */
       foreach_list_safe(entry_node, aeb) {
         aeb_entry *entry = (aeb_entry *)entry_node;
 
         for (int i = 0; i < 3; i++) {
+            fs_reg *src_reg = &entry->generator->src[i];
+
+            /* Kill all AEB entries that use the destination we just
+             * overwrote.
+             */
             if (inst->overwrites_reg(entry->generator->src[i])) {
               entry->remove();
               ralloc_free(entry);
               break;
            }
+
+            /* Kill any AEB entries using registers that don't get reused any
+             * more -- a sure sign they'll fail operands_match().
+             */
+            if (src_reg->file == GRF && virtual_grf_end[src_reg->reg] < ip) {
+               entry->remove();
+               ralloc_free(entry);
+              break;
+            }
         }
       }
+
+      ip++;
    }
 
    ralloc_free(mem_ctx);
@@ -181,6 +218,8 @@ fs_visitor::opt_cse()
 {
    bool progress = false;
 
+   calculate_live_intervals();
+
    cfg_t cfg(this);
 
    for (int b = 0; b < cfg.num_blocks; b++) {