From 3850922b780a8c87e0338860a5381a85b44f2c7d Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 8 May 2026 08:49:03 -0700 Subject: [PATCH] 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 Part-of: --- src/intel/compiler/brw/brw_opt_register_coalesce.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/intel/compiler/brw/brw_opt_register_coalesce.cpp b/src/intel/compiler/brw/brw_opt_register_coalesce.cpp index 24f09ecb63d..336a37afdf0 100644 --- a/src/intel/compiler/brw/brw_opt_register_coalesce.cpp +++ b/src/intel/compiler/brw/brw_opt_register_coalesce.cpp @@ -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) {