From bccfc34ca3f58a2e6706fa37bc0729a56f35bc1f Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Sat, 15 Aug 2015 20:49:20 -0400 Subject: [PATCH] make sure eflags-writing do not disappear This is a hack implementation, ideally I would like something cleaner. The problem is that regalloc thinks an instruction is dead code because it's not aware that it writes to eflags. --- lisc/emit.c | 2 ++ lisc/isel.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lisc/emit.c b/lisc/emit.c index d5b1e80..00bce4b 100644 --- a/lisc/emit.c +++ b/lisc/emit.c @@ -173,6 +173,8 @@ eins(Ins i, Fn *fn, FILE *f) eop(otoa[i.op], i.arg[1], i.to, fn, f); break; case OCopy: + if (req(i.to, R)) + break; if (i.to.val < EAX && rtype(i.arg[0]) == RCon) { val = fn->con[i.arg[0].val].val; if (0 <= val && val <= UINT32_MAX) { diff --git a/lisc/isel.c b/lisc/isel.c index 6f2147f..97a0124 100644 --- a/lisc/isel.c +++ b/lisc/isel.c @@ -318,8 +318,11 @@ seljmp(Blk *b, Fn *fn) selcmp(fi->arg, fn); *fi = (Ins){ONop, R, {R, R}}; } - } else + } else { + if (fn->tmp[r.val].nuse == 1) + emit(OCopy, R, r, R); b->jmp.type = JXJc + Cne; + } } else { selcmp((Ref[2]){r, CON_Z}, fn); b->jmp.type = JXJc + Cne;