i965/compute: Fix uniform init issue when SIMD8 is skipped
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs_saturate_propagation.cpp
index 0c48dcd180c968d42185b4114c33e09b9a59eba8..f59fdbddfa69c08c827f19f3407605d94ee16b4d 100644 (file)
@@ -53,11 +53,10 @@ opt_saturate_propagation_local(fs_visitor *v, bblock_t *block)
 
       if (inst->opcode != BRW_OPCODE_MOV ||
           !inst->saturate ||
-          inst->dst.file != GRF ||
+          inst->dst.file != VGRF ||
           inst->dst.type != inst->src[0].type ||
-          inst->src[0].file != GRF ||
-          inst->src[0].abs ||
-          inst->src[0].negate)
+          inst->src[0].file != VGRF ||
+          inst->src[0].abs)
          continue;
 
       int src_var = v->live_intervals->var_from_reg(inst->src[0]);
@@ -74,7 +73,7 @@ opt_saturate_propagation_local(fs_visitor *v, bblock_t *block)
             if (scan_inst->saturate) {
                inst->saturate = false;
                progress = true;
-            } else if (src_end_ip <= ip || inst->dst.equals(inst->src[0])) {
+            } else if (src_end_ip == ip || inst->dst.equals(inst->src[0])) {
                if (scan_inst->can_do_saturate()) {
                   if (scan_inst->dst.type != inst->dst.type) {
                      scan_inst->dst.type = inst->dst.type;
@@ -82,6 +81,31 @@ opt_saturate_propagation_local(fs_visitor *v, bblock_t *block)
                         scan_inst->src[i].type = inst->dst.type;
                      }
                   }
+
+                  if (inst->src[0].negate) {
+                     if (scan_inst->opcode == BRW_OPCODE_MUL) {
+                        scan_inst->src[0].negate = !scan_inst->src[0].negate;
+                        inst->src[0].negate = false;
+                     } else if (scan_inst->opcode == BRW_OPCODE_MAD) {
+                        scan_inst->src[0].negate = !scan_inst->src[0].negate;
+                        scan_inst->src[1].negate = !scan_inst->src[1].negate;
+                        inst->src[0].negate = false;
+                     } else if (scan_inst->opcode == BRW_OPCODE_ADD) {
+                        if (scan_inst->src[1].file == IMM) {
+                           if (!brw_negate_immediate(scan_inst->src[1].type,
+                                                     &scan_inst->src[1].as_brw_reg())) {
+                              break;
+                           }
+                        } else {
+                           scan_inst->src[1].negate = !scan_inst->src[1].negate;
+                        }
+                        scan_inst->src[0].negate = !scan_inst->src[0].negate;
+                        inst->src[0].negate = false;
+                     } else {
+                        break;
+                     }
+                  }
+
                   scan_inst->saturate = true;
                   inst->saturate = false;
                   progress = true;
@@ -90,13 +114,15 @@ opt_saturate_propagation_local(fs_visitor *v, bblock_t *block)
             break;
          }
          for (int i = 0; i < scan_inst->sources; i++) {
-            if (scan_inst->src[i].file == GRF &&
+            if (scan_inst->src[i].file == VGRF &&
                 scan_inst->src[i].nr == inst->src[0].nr &&
                 scan_inst->src[i].reg_offset == inst->src[0].reg_offset) {
                if (scan_inst->opcode != BRW_OPCODE_MOV ||
                    !scan_inst->saturate ||
                    scan_inst->src[0].abs ||
-                   scan_inst->src[0].negate) {
+                   scan_inst->src[0].negate ||
+                   scan_inst->src[0].abs != inst->src[0].abs ||
+                   scan_inst->src[0].negate != inst->src[0].negate) {
                   interfered = true;
                   break;
                }