Revert "Eliminate duplicate spill loads at the same basic block"

This reverts commit 5d05d78462.
This commit is contained in:
Dmitry Stogov 2023-06-22 01:58:26 +03:00
parent 5d05d78462
commit 35f94d570f
11 changed files with 46 additions and 49 deletions

55
ir_ra.c
View File

@ -3561,13 +3561,11 @@ static void assign_regs(ir_ctx *ctx)
if (ival) { if (ival) {
do { do {
if (ival->reg != IR_REG_NONE) { if (ival->reg != IR_REG_NONE) {
ir_ref prev_use_ref = IR_UNUSED;
IR_REGSET_INCL(used_regs, ival->reg); IR_REGSET_INCL(used_regs, ival->reg);
use_pos = ival->use_pos; use_pos = ival->use_pos;
while (use_pos) { while (use_pos) {
reg = ival->reg; reg = ival->reg;
ref = IR_LIVE_POS_TO_REF(use_pos->pos); ref = (use_pos->hint_ref < 0) ? -use_pos->hint_ref : IR_LIVE_POS_TO_REF(use_pos->pos);
if (use_pos->op_num == 0 if (use_pos->op_num == 0
&& (use_pos->flags & IR_DEF_REUSES_OP1_REG) && (use_pos->flags & IR_DEF_REUSES_OP1_REG)
&& ctx->regs[ref][1] != IR_REG_NONE && ctx->regs[ref][1] != IR_REG_NONE
@ -3594,51 +3592,31 @@ static void assign_regs(ir_ctx *ctx)
// TODO: Insert spill loads and stotres in optimal positons (resolution) // TODO: Insert spill loads and stotres in optimal positons (resolution)
if (use_pos->op_num == 0) { if (use_pos->op_num == 0) {
if (ctx->ir_base[ref].op == IR_PHI) { if (top_ival->flags & IR_LIVE_INTERVAL_SPILL_SPECIAL) {
/* Spilled PHI var is passed through memory */ reg |= IR_REG_SPILL_SPECIAL;
reg = IR_REG_NONE;
} else { } else {
if (top_ival->flags & IR_LIVE_INTERVAL_SPILL_SPECIAL) { reg |= IR_REG_SPILL_STORE;
reg |= IR_REG_SPILL_SPECIAL;
} else {
reg |= IR_REG_SPILL_STORE;
}
prev_use_ref = ref;
} }
} else if (!prev_use_ref } else {
|| ctx->cfg_map[prev_use_ref] != ctx->cfg_map[ref]) { if ((use_pos->flags & IR_USE_MUST_BE_IN_REG)
if (!(use_pos->flags & IR_USE_MUST_BE_IN_REG) || ctx->ir_base[ref].op == IR_CALL
&& use_pos->hint != reg || ctx->ir_base[ref].op == IR_TAILCALL
// && ctx->ir_base[ref].op != IR_CALL || ctx->ir_base[ref].op == IR_SNAPSHOT) {
// && ctx->ir_base[ref].op != IR_TAILCALL) {
&& ctx->ir_base[ref].op != IR_SNAPSHOT) {
/* fuse spill load (valid only when register is not reused) */
reg = IR_REG_NONE;
} else {
if (top_ival->flags & IR_LIVE_INTERVAL_SPILL_SPECIAL) { if (top_ival->flags & IR_LIVE_INTERVAL_SPILL_SPECIAL) {
reg |= IR_REG_SPILL_SPECIAL; reg |= IR_REG_SPILL_SPECIAL;
} else { } else {
reg |= IR_REG_SPILL_LOAD; reg |= IR_REG_SPILL_LOAD;
} }
if (ctx->ir_base[ref].op != IR_SNAPSHOT) { } else if (use_pos->op_num == 2
prev_use_ref = ref; && ctx->ir_base[ref].op1 == ctx->ir_base[ref].op2
} && IR_REG_NUM(ctx->regs[ref][1]) == reg) {
} /* pass */
} else if (use_pos->flags & IR_PHI_USE) { } else {
IR_ASSERT(use_pos->hint_ref < 0); /* fuse spill load (valid only when register is not reused) */
IR_ASSERT(ctx->vregs[-use_pos->hint_ref]);
IR_ASSERT(ctx->live_intervals[ctx->vregs[-use_pos->hint_ref]]);
if (ctx->live_intervals[ctx->vregs[-use_pos->hint_ref]]->flags & IR_LIVE_INTERVAL_SPILLED) {
/* Spilled PHI var is passed through memory */
reg = IR_REG_NONE; reg = IR_REG_NONE;
} }
} else {
/* reuse register without spill load */
} }
} }
if (use_pos->hint_ref < 0) {
ref = -use_pos->hint_ref;
}
ir_set_alocated_reg(ctx, ref, use_pos->op_num, reg); ir_set_alocated_reg(ctx, ref, use_pos->op_num, reg);
use_pos = use_pos->next; use_pos = use_pos->next;
@ -3647,9 +3625,8 @@ static void assign_regs(ir_ctx *ctx)
&& !(top_ival->flags & IR_LIVE_INTERVAL_SPILL_SPECIAL)) { && !(top_ival->flags & IR_LIVE_INTERVAL_SPILL_SPECIAL)) {
use_pos = ival->use_pos; use_pos = ival->use_pos;
while (use_pos) { while (use_pos) {
ref = IR_LIVE_POS_TO_REF(use_pos->pos); ref = (use_pos->hint_ref < 0) ? -use_pos->hint_ref : IR_LIVE_POS_TO_REF(use_pos->pos);
if (ctx->ir_base[ref].op == IR_SNAPSHOT) { if (ctx->ir_base[ref].op == IR_SNAPSHOT) {
IR_ASSERT(use_pos->hint_ref >= 0);
/* A reference to a CPU spill slot */ /* A reference to a CPU spill slot */
reg = IR_REG_SPILL_STORE | IR_REG_STACK_POINTER; reg = IR_REG_SPILL_STORE | IR_REG_STACK_POINTER;
ir_set_alocated_reg(ctx, ref, use_pos->op_num, reg); ir_set_alocated_reg(ctx, ref, use_pos->op_num, reg);

View File

@ -89,8 +89,11 @@ test:
ldr d0, [x29, #0x10] ldr d0, [x29, #0x10]
fadd d1, d1, d0 fadd d1, d1, d0
str d1, [x29, #0x18] str d1, [x29, #0x18]
ldr d1, [x29, #0x18]
ldr d0, [x29, #0x10]
fsub d0, d1, d0 fsub d0, d1, d0
str d0, [x29, #0x10] str d0, [x29, #0x10]
ldr d0, [x29, #0x10]
adr x0, .L5 adr x0, .L5
bl _IO_printf bl _IO_printf
b .L1 b .L1
@ -99,6 +102,7 @@ test:
ldp x29, x30, [sp], #0x20 ldp x29, x30, [sp], #0x20
ret ret
.rodata .rodata
.db 0x1f, 0x20, 0x03, 0xd5
.L3: .L3:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f
.L4: .L4:

View File

@ -89,8 +89,11 @@ test:
ldr d0, [x29, #0x10] ldr d0, [x29, #0x10]
fadd d1, d1, d0 fadd d1, d1, d0
str d1, [x29, #0x18] str d1, [x29, #0x18]
ldr d1, [x29, #0x18]
ldr d0, [x29, #0x10]
fsub d0, d1, d0 fsub d0, d1, d0
str d0, [x29, #0x10] str d0, [x29, #0x10]
ldr d0, [x29, #0x10]
adr x0, .L5 adr x0, .L5
bl _IO_printf bl _IO_printf
adr x0, .L5 adr x0, .L5
@ -102,7 +105,6 @@ test:
ldp x29, x30, [sp], #0x20 ldp x29, x30, [sp], #0x20
ret ret
.rodata .rodata
.db 0x1f, 0x20, 0x03, 0xd5
.L3: .L3:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f
.L4: .L4:

View File

@ -167,6 +167,8 @@ test:
ldr d0, [sp, #0x10] ldr d0, [sp, #0x10]
fmul d0, d0, d0 fmul d0, d0, d0
str d0, [sp, #0x28] str d0, [sp, #0x28]
ldr d0, [sp, #0x28]
ldr d1, [sp, #0x20]
fadd d0, d0, d1 fadd d0, d0, d1
ldr d1, .L5 ldr d1, .L5
fcmp d0, d1 fcmp d0, d1

View File

@ -78,14 +78,15 @@ test:
movl %edx, %ebp movl %edx, %ebp
imull %ecx, %ebp imull %ecx, %ebp
movl %ebp, (%esp) movl %ebp, (%esp)
movl (%esp), %ebp
leal 4(%ebp), %ebp leal 4(%ebp), %ebp
movl %ebp, 4(%esp) movl %ebp, 4(%esp)
.L1: .L1:
cmpl $0, 0x3c(%esp) cmpl $0, 0x3c(%esp)
je .L3 je .L3
movl 4(%esp), %eax
movl %eax, 0x30(%esp)
movl %edx, %eax movl %edx, %eax
movl 4(%esp), %ebp
movl %ebp, 0x30(%esp)
.L2: .L2:
cmpl $0, 0x40(%esp) cmpl $0, 0x40(%esp)
jne .L1 jne .L1
@ -113,6 +114,7 @@ test:
movl %eax, %esi movl %eax, %esi
imull %ecx, %esi imull %ecx, %esi
movl %esi, 0x34(%esp) movl %esi, 0x34(%esp)
movl 0x34(%esp), %esi
leal 1(%esi), %edi leal 1(%esi), %edi
movl %edi, 0x38(%esp) movl %edi, 0x38(%esp)
movl %edx, %ebx movl %edx, %ebx

View File

@ -84,10 +84,12 @@ test:
movsd 0xc(%esp), %xmm0 movsd 0xc(%esp), %xmm0
addsd %xmm1, %xmm0 addsd %xmm1, %xmm0
movsd %xmm0, 0xc(%esp) movsd %xmm0, 0xc(%esp)
movsd 0xc(%esp), %xmm0
subsd %xmm1, %xmm0 subsd %xmm1, %xmm0
movsd %xmm0, 0x14(%esp) movsd %xmm0, 0x14(%esp)
movsd %xmm0, 4(%esp)
movl $.L5, (%esp) movl $.L5, (%esp)
movsd 0x14(%esp), %xmm0
movsd %xmm0, 4(%esp)
calll printf calll printf
movsd 0x14(%esp), %xmm1 movsd 0x14(%esp), %xmm1
jmp .L1 jmp .L1
@ -96,7 +98,7 @@ test:
addl $0x1c, %esp addl $0x1c, %esp
retl retl
.rodata .rodata
.db 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 .db 0x90, 0x90, 0x90
.L3: .L3:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f
.L4: .L4:

View File

@ -84,10 +84,12 @@ test:
movsd 0xc(%esp), %xmm0 movsd 0xc(%esp), %xmm0
addsd %xmm1, %xmm0 addsd %xmm1, %xmm0
movsd %xmm0, 0xc(%esp) movsd %xmm0, 0xc(%esp)
movsd 0xc(%esp), %xmm0
subsd %xmm1, %xmm0 subsd %xmm1, %xmm0
movsd %xmm0, 0x14(%esp) movsd %xmm0, 0x14(%esp)
movsd %xmm0, 4(%esp)
movl $.L5, (%esp) movl $.L5, (%esp)
movsd 0x14(%esp), %xmm0
movsd %xmm0, 4(%esp)
calll printf calll printf
movl $.L5, (%esp) movl $.L5, (%esp)
movsd 0x14(%esp), %xmm7 movsd 0x14(%esp), %xmm7
@ -100,7 +102,7 @@ test:
addl $0x1c, %esp addl $0x1c, %esp
retl retl
.rodata .rodata
.db 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 .db 0x90, 0x90, 0x90
.L3: .L3:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f
.L4: .L4:

View File

@ -153,6 +153,7 @@ test:
movapd %xmm1, %xmm0 movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0 mulsd %xmm1, %xmm0
movsd %xmm0, 0x18(%esp) movsd %xmm0, 0x18(%esp)
movsd 0x18(%esp), %xmm0
addsd 0x10(%esp), %xmm0 addsd 0x10(%esp), %xmm0
ucomisd .L5, %xmm0 ucomisd .L5, %xmm0
ja .L2 ja .L2
@ -174,7 +175,6 @@ test:
addl $0x20, %esp addl $0x20, %esp
retl retl
.rodata .rodata
.db 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
.L4: .L4:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f
.L5: .L5:

View File

@ -86,8 +86,10 @@ test:
movsd (%rsp), %xmm0 movsd (%rsp), %xmm0
addsd %xmm1, %xmm0 addsd %xmm1, %xmm0
movsd %xmm0, (%rsp) movsd %xmm0, (%rsp)
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0 subsd %xmm1, %xmm0
movsd %xmm0, 8(%rsp) movsd %xmm0, 8(%rsp)
movsd 8(%rsp), %xmm0
leaq .L5(%rip), %rdi leaq .L5(%rip), %rdi
movabsq $_IO_printf, %rax movabsq $_IO_printf, %rax
callq *%rax callq *%rax
@ -98,6 +100,7 @@ test:
addq $0x18, %rsp addq $0x18, %rsp
retq retq
.rodata .rodata
.db 0x90, 0x90, 0x90, 0x90, 0x90
.L3: .L3:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f
.L4: .L4:

View File

@ -86,8 +86,10 @@ test:
movsd (%rsp), %xmm0 movsd (%rsp), %xmm0
addsd %xmm1, %xmm0 addsd %xmm1, %xmm0
movsd %xmm0, (%rsp) movsd %xmm0, (%rsp)
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0 subsd %xmm1, %xmm0
movsd %xmm0, 8(%rsp) movsd %xmm0, 8(%rsp)
movsd 8(%rsp), %xmm0
leaq .L5(%rip), %rdi leaq .L5(%rip), %rdi
movabsq $_IO_printf, %rax movabsq $_IO_printf, %rax
callq *%rax callq *%rax
@ -102,7 +104,7 @@ test:
addq $0x18, %rsp addq $0x18, %rsp
retq retq
.rodata .rodata
.db 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 .db 0x90, 0x90, 0x90, 0x90
.L3: .L3:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f
.L4: .L4:

View File

@ -155,6 +155,7 @@ test:
movapd %xmm1, %xmm0 movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0 mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp) movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0 addsd 0x18(%rsp), %xmm0
ucomisd .L5(%rip), %xmm0 ucomisd .L5(%rip), %xmm0
ja .L2 ja .L2
@ -176,7 +177,7 @@ test:
addq $0x28, %rsp addq $0x28, %rsp
retq retq
.rodata .rodata
.db 0x90, 0x90, 0x90 .db 0x90, 0x90, 0x90, 0x90, 0x90
.L4: .L4:
.db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f .db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f
.L5: .L5: