brw: Save original regs_written() value in register coalesce

The instruction may get transformed, modifying the destination before
the loop index gets incremented.  So save the original regs_written
value to be used in the loop increment.

While we are here, assert that all the slots in mov[] are filled
at this point in the code.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41496>
This commit is contained in:
Caio Oliveira 2026-05-08 08:49:03 -07:00 committed by Marge Bot
parent ec778a297f
commit 3850922b78

View file

@ -319,6 +319,9 @@ brw_opt_register_coalesce(brw_shader &s)
if (channels_remaining)
continue;
for (int i = 0; i < src_size; i++)
assert(mov[i]);
bool can_coalesce = true;
for (int i = 0; i < src_size; i++) {
if (dst_reg_offset[i] != dst_reg_offset[0] + i) {
@ -344,9 +347,9 @@ brw_opt_register_coalesce(brw_shader &s)
progress = true;
for (int i = 0; i < src_size; i += regs_written(mov[i])) {
if (!mov[i])
continue;
for (int i = 0; i < src_size; ) {
assert(mov[i]);
const unsigned written = regs_written(mov[i]);
if (mov[i]->conditional_mod == BRW_CONDITIONAL_NONE) {
mov[i] = brw_transform_inst(s, mov[i], BRW_OPCODE_NOP);
@ -366,6 +369,8 @@ brw_opt_register_coalesce(brw_shader &s)
mov[i]->src[0] = mov[i]->dst;
mov[i]->dst = retype(brw_null_reg(), mov[i]->dst.type);
}
i += written;
}
foreach_block_and_inst(block, brw_inst, scan_inst, s.cfg) {