x86/x64: Fix code generation for fused test/arith ops.

Thanks to Alexander Nasonov and AFL.
This commit is contained in:
Mike Pall 2015-02-21 21:44:41 +01:00
parent 704280fb80
commit 4fa51affe8

View File

@ -1836,8 +1836,12 @@ static void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa)
Reg dest, right;
int32_t k = 0;
if (as->flagmcp == as->mcp) { /* Drop test r,r instruction. */
MCode *p = as->mcp + ((LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2);
if ((p[1] & 15) < 14) {
if ((p[1] & 15) >= 12) p[1] -= 4; /* L <->S, NL <-> NS */
as->flagmcp = NULL;
as->mcp += (LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2;
as->mcp = p;
} /* else: cannot transform LE/NLE to cc without use of OF. */
}
right = IR(rref)->r;
if (ra_hasreg(right)) {