- if (inst->dst.writemask == 0) {
- if (inst->writes_accumulator || inst->writes_flag()) {
- inst->dst = dst_reg(retype(brw_null_reg(), inst->dst.type));
- } else {
- inst->opcode = BRW_OPCODE_NOP;
- break;
+ /* If none of the destination components are read, replace the
+ * destination register with the NULL register.
+ */
+ if (dest_mask == 0) {
+ progress = true;
+ inst->dst = dst_reg(retype(brw_null_reg(), inst->dst.type));
+ }
+ } else {
+ for (int c = 0; c < 4; c++) {
+ if (!result_live[c] && inst->dst.writemask & (1 << c)) {
+ inst->dst.writemask &= ~(1 << c);
+ progress = true;
+
+ if (inst->dst.writemask == 0) {
+ if (inst->writes_accumulator) {
+ inst->dst = dst_reg(retype(brw_null_reg(), inst->dst.type));
+ } else {
+ inst->opcode = BRW_OPCODE_NOP;
+ break;
+ }