Skip to content

Commit

Permalink
More accurate swap/overlap check
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Apr 10, 2024
1 parent 412c657 commit 04b682d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions ir_ra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1932,20 +1932,33 @@ int ir_coalesce(ir_ctx *ctx)
IR_ASSERT(ir_op_flags[input_insn->op] & IR_OP_FLAG_COMMUTATIVE);
if (input_insn->op2 == use
&& input_insn->op1 != use
&& (ctx->live_intervals[v1]->use_pos->flags & IR_DEF_REUSES_OP1_REG)
&& ctx->live_intervals[v2]->end == IR_USE_LIVE_POS_FROM_REF(input)) {
&& (ctx->live_intervals[v1]->use_pos->flags & IR_DEF_REUSES_OP1_REG)) {
ir_live_range *r = &ctx->live_intervals[v2]->range;

while (r->next) {
do {
if (r->end == IR_USE_LIVE_POS_FROM_REF(input)) {
break;
}
r = r->next;
} while (r);
if (r) {
r->end = IR_LOAD_LIVE_POS_FROM_REF(input);
if (!r->next) {
ctx->live_intervals[v2]->end = IR_LOAD_LIVE_POS_FROM_REF(input);
}
if (ir_vregs_overlap(ctx, v1, v2)) {
r->end = IR_USE_LIVE_POS_FROM_REF(input);
if (!r->next) {
ctx->live_intervals[v2]->end = IR_USE_LIVE_POS_FROM_REF(input);
}
} else {
ir_swap_operands(ctx, input, input_insn);
IR_ASSERT(!ir_vregs_overlap(ctx, v1, v2));
ir_vregs_coalesce(ctx, v1, v2, input, use);
compact = 1;
continue;
}
}
r->end = IR_LOAD_LIVE_POS_FROM_REF(input);
ctx->live_intervals[v2]->end = IR_LOAD_LIVE_POS_FROM_REF(input);
ir_swap_operands(ctx, input, input_insn);
IR_ASSERT(!ir_vregs_overlap(ctx, v1, v2));
ir_vregs_coalesce(ctx, v1, v2, input, use);
compact = 1;
continue;
}
}
#endif
Expand Down

0 comments on commit 04b682d

Please sign in to comment.