aboutsummaryrefslogtreecommitdiffhomepage
path: root/x86_64
diff options
context:
space:
mode:
Diffstat (limited to 'x86_64')
-rw-r--r--x86_64/emit.c10
-rw-r--r--x86_64/isel.c9
2 files changed, 5 insertions, 14 deletions
diff --git a/x86_64/emit.c b/x86_64/emit.c
index 13121b3..89585b8 100644
--- a/x86_64/emit.c
+++ b/x86_64/emit.c
@@ -1171,16 +1171,6 @@ emitinstr(uchar **pcode, struct function *fn, struct block *blk, int curi, struc
Xpop(pcode, mkregoper(ins->l).reg);
break;
case Ocall:
- if (calltab.p[ins->r.i].vararg >= 0) {
- struct call *call = &calltab.p[ins->r.i];
- /* variadic functions need the caller to write num of args in sse regs to %al */
- int n = 0;
- for (int i = 0; i < call->narg; ++i)
- if (!call->abiarg[i].isstk && call->abiarg[i].reg >= XMM0)
- ++n;
- if (!n) DS("\x31\xC0"); /* XOR EAX, EAX */
- else B(0xB0), B(n); /* MOV AL, n */
- }
Xcall(pcode, KPTR, ref2oper(ins->l));
break;
case Oxvaprologue:
diff --git a/x86_64/isel.c b/x86_64/isel.c
index 67a4358..22a1290 100644
--- a/x86_64/isel.c
+++ b/x86_64/isel.c
@@ -126,6 +126,7 @@ selcall(struct function *fn, struct instr *ins, struct block *blk, int *curi)
int iarg = *curi - 1;
enum irclass cls;
uint argstksiz = alignup(call->argstksiz, 16);
+ int nsse = 0;
for (int i = call->narg - 1; i >= 0; --i) {
struct abiarg abi = call->abiarg[i];
@@ -139,6 +140,7 @@ selcall(struct function *fn, struct instr *ins, struct block *blk, int *curi)
if (!abi.isstk) {
assert(!abi.ty.isagg);
*arg = mkinstr(Omove, call->abiarg[i].ty.cls, mkref(RREG, abi.reg), arg->r);
+ if (abi.reg >= XMM0) ++nsse;
} else {
union ref adr = mkaddr((struct addr){mkref(RREG, RSP), .disp = abi.stk});
int iargsave = iarg;
@@ -165,10 +167,9 @@ selcall(struct function *fn, struct instr *ins, struct block *blk, int *curi)
else if (isintcon(ins->l))
ins->l = insertinstr(blk, (*curi)++, mkinstr(Ocopy, KPTR, ins->l));
- if (call->vararg >= 0 && ins->l.t == RTMP) {
- /* variadic calls write number of sse regs used to AL, so mark it as clobbered such that
- * the function pointer of an indirect calls does not get allocated to RAX by regalloc */
- insertinstr(blk, (*curi)++, mkinstr(Omove, KPTR, mkref(RREG, RAX), mkref(RREG, RAX)));
+ if (call->vararg >= 0) {
+ /* variadic calls write number of sse regs used to AL */
+ insertinstr(blk, (*curi)++, mkinstr(Omove, KI32, mkref(RREG, RAX), mkref(RICON, nsse), .keep=1));
}
cls = ins->cls;
ins->cls = 0;