static bool
can_coalesce_vars(brw::fs_live_variables *live_intervals,
- const exec_list *instructions, const fs_inst *inst,
+ const exec_list *instructions, const fs_inst *inst, int ip,
int var_to, int var_from)
{
if (!live_intervals->vars_interfere(var_from, var_to))
if (live_intervals->end[var_to] > live_intervals->end[var_from])
return false;
- int scan_ip = -1;
-
- foreach_list(n, instructions) {
- fs_inst *scan_inst = (fs_inst *)n;
- scan_ip++;
+ assert(ip >= live_intervals->start[var_to]);
+ fs_inst *scan_inst;
+ for (scan_inst = (fs_inst *)inst->next;
+ !scan_inst->is_tail_sentinel() && ip <= live_intervals->end[var_to];
+ scan_inst = (fs_inst *)scan_inst->next, ip++) {
if (scan_inst->is_control_flow())
return false;
- if (scan_ip <= live_intervals->start[var_to])
- continue;
-
- if (scan_ip > live_intervals->end[var_to])
- break;
-
if (scan_inst->dst.equals(inst->dst) ||
scan_inst->dst.equals(inst->src[0]))
return false;
fs_inst *mov[MAX_SAMPLER_MESSAGE_SIZE];
int var_to[MAX_SAMPLER_MESSAGE_SIZE];
int var_from[MAX_SAMPLER_MESSAGE_SIZE];
+ int ip = -1;
foreach_list(node, &this->instructions) {
fs_inst *inst = (fs_inst *)node;
+ ip++;
if (!is_coalesce_candidate(inst, virtual_grf_sizes))
continue;
var_to[i] = live_intervals->var_from_vgrf[reg_to] + reg_to_offset[i];
var_from[i] = live_intervals->var_from_vgrf[reg_from] + i;
- if (!can_coalesce_vars(live_intervals, &instructions, inst,
+ if (!can_coalesce_vars(live_intervals, &instructions, inst, ip,
var_to[i], var_from[i])) {
can_coalesce = false;
reg_from = -1;