i965/urb: fixes division by zero
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs_cmod_propagation.cpp
index 1935f06df0b0a6e91647cf4081fdc45ce4cc7ab7..b5badaef9774e375c76eb1cdf09ca50a20568d15 100644 (file)
@@ -22,8 +22,8 @@
  */
 
 #include "brw_fs.h"
-#include "brw_fs_live_variables.h"
 #include "brw_cfg.h"
+#include "brw_eu.h"
 
 /** @file brw_fs_cmod_propagation.cpp
  *
@@ -62,7 +62,7 @@ opt_cmod_propagation_local(bblock_t *block)
            inst->opcode != BRW_OPCODE_MOV) ||
           inst->predicate != BRW_PREDICATE_NONE ||
           !inst->dst.is_null() ||
-          inst->src[0].file != GRF ||
+          inst->src[0].file != VGRF ||
           inst->src[0].abs)
          continue;
 
@@ -87,30 +87,33 @@ opt_cmod_propagation_local(bblock_t *block)
          continue;
 
       bool read_flag = false;
-      foreach_inst_in_block_reverse_starting_from(fs_inst, scan_inst, inst,
-                                                  block) {
+      foreach_inst_in_block_reverse_starting_from(fs_inst, scan_inst, inst) {
          if (scan_inst->overwrites_reg(inst->src[0])) {
             if (scan_inst->is_partial_write() ||
-                scan_inst->dst.reg_offset != inst->src[0].reg_offset)
+                scan_inst->dst.reg_offset != inst->src[0].reg_offset ||
+                scan_inst->exec_size != inst->exec_size)
                break;
 
-            /* This must be done before the dst.type check because the result
-             * type of the AND will always be D, but the result of the CMP
-             * could be anything.  The assumption is that the AND is just
-             * figuring out what the result of the previous comparison was
-             * instead of doing a new comparison with a different type.
-             */
-            if (inst->opcode == BRW_OPCODE_AND) {
-               if (scan_inst->opcode == BRW_OPCODE_CMP) {
-                  inst->remove(block);
-                  progress = true;
-               }
-
+            /* CMP's result is the same regardless of dest type. */
+            if (inst->conditional_mod == BRW_CONDITIONAL_NZ &&
+                scan_inst->opcode == BRW_OPCODE_CMP &&
+                (inst->dst.type == BRW_REGISTER_TYPE_D ||
+                 inst->dst.type == BRW_REGISTER_TYPE_UD)) {
+               inst->remove(block);
+               progress = true;
                break;
             }
 
+            /* If the AND wasn't handled by the previous case, it isn't safe
+             * to remove it.
+             */
+            if (inst->opcode == BRW_OPCODE_AND)
+               break;
+
             /* Comparisons operate differently for ints and floats */
-            if (scan_inst->dst.type != inst->dst.type)
+            if (scan_inst->dst.type != inst->dst.type &&
+                (scan_inst->dst.type == BRW_REGISTER_TYPE_F ||
+                 inst->dst.type == BRW_REGISTER_TYPE_F))
                break;
 
             /* If the instruction generating inst's source also wrote the