-
Notifications
You must be signed in to change notification settings - Fork 31
Prevent clobbering of TAILCALL op2 in epilogue #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the attempt to fix this and for the new test cases.
I think, the idea should work, but I see few problems.
See comments...
We probably should also check for %rsp
and %rbp
in the fused memory load.
if (IR_REG_SPILLED(op2_reg)) { | ||
op2_reg = IR_REG_NUM(op2_reg); | ||
ir_emit_load(ctx, IR_ADDR, op2_reg, insn->op2); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a spilled op2_reg
that not interference with ctx->used_preserved_reg
?
I think you lost this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I missed this case. I've updated the PR and added tests for that.
ir_x86.dasc
Outdated
op2_reg = IR_REG_RAX; | ||
|
||
ir_type type = ctx->ir_base[insn->op2].type; | ||
| ASM_REG_MEM_OP, mov, type, op2_reg, mem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ir_emit_load_mem_int()
tests/x86_64/tailcall_002.irt
Outdated
movq %rbx, (%rsp) | ||
callq *%rbx | ||
movq %rbx, %rdi | ||
addq $0x10, %rsp | ||
popq %rbx | ||
jmpq *(%rsp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks wrong. %rsp
is changed between movq %rbx, (%rsp)
and jmpq *(%rsp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I didn't notice that
TAILCALL op2 may be overridden when it is assigned to a preserved register, as the epilogue is emitted before the call:
This can not be trivially solved in RA, as the set of used preserved regs is not known yet.
Here I move op2 to a tmp reg in
ir_emit_tailcall()
when op2 is inused_preserved_regs
.