diff --git a/src/intel/compiler/brw/brw_opt_register_coalesce.cpp b/src/intel/compiler/brw/brw_opt_register_coalesce.cpp index 336a37afdf0..448d6480240 100644 --- a/src/intel/compiler/brw/brw_opt_register_coalesce.cpp +++ b/src/intel/compiler/brw/brw_opt_register_coalesce.cpp @@ -373,20 +373,40 @@ brw_opt_register_coalesce(brw_shader &s) i += written; } - foreach_block_and_inst(block, brw_inst, scan_inst, s.cfg) { - if (scan_inst->dst.file == VGRF && - scan_inst->dst.nr == src_reg) { - scan_inst->dst.nr = dst_reg; - scan_inst->dst.offset = scan_inst->dst.offset % REG_SIZE + - dst_reg_offset[scan_inst->dst.offset / REG_SIZE] * REG_SIZE; - } + brw_range rewrite_range = { 0, 0 }; + for (int i = 0; i < src_size; i++) + rewrite_range = merge(rewrite_range, live.vars_range[src_var[i]]); + assert(!rewrite_range.is_empty()); - for (int j = 0; j < scan_inst->sources; j++) { - if (scan_inst->src[j].file == VGRF && - scan_inst->src[j].nr == src_reg) { - scan_inst->src[j].nr = dst_reg; - scan_inst->src[j].offset = scan_inst->src[j].offset % REG_SIZE + - dst_reg_offset[scan_inst->src[j].offset / REG_SIZE] * REG_SIZE; + foreach_block(block, s.cfg) { + if (ips.range(block).last() < rewrite_range.start) + continue; + if (ips.range(block).start > rewrite_range.last()) + break; + + int scan_ip = ips.range(block).start - 1; + foreach_inst_in_block(brw_inst, scan_inst, block) { + scan_ip++; + + if (scan_ip < rewrite_range.start) + continue; + if (scan_ip > rewrite_range.last()) + break; + + if (scan_inst->dst.file == VGRF && + scan_inst->dst.nr == src_reg) { + scan_inst->dst.nr = dst_reg; + scan_inst->dst.offset = scan_inst->dst.offset % REG_SIZE + + dst_reg_offset[scan_inst->dst.offset / REG_SIZE] * REG_SIZE; + } + + for (int j = 0; j < scan_inst->sources; j++) { + if (scan_inst->src[j].file == VGRF && + scan_inst->src[j].nr == src_reg) { + scan_inst->src[j].nr = dst_reg; + scan_inst->src[j].offset = scan_inst->src[j].offset % REG_SIZE + + dst_reg_offset[scan_inst->src[j].offset / REG_SIZE] * REG_SIZE; + } } } }