]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
x86/x64: Fix code generation for fused test/arith ops.
authorMike Pall <mike>
Sat, 21 Feb 2015 20:44:41 +0000 (21:44 +0100)
committerMike Pall <mike>
Sat, 21 Feb 2015 20:44:41 +0000 (21:44 +0100)
Thanks to Alexander Nasonov and AFL.

src/lj_asm_x86.h

index bb6976f2c54459f63cb2bbe125d5f4211ea9b940..0b6b2d4a5a70780ff393195e0626f8f52e9c8644 100644 (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. */
-    as->flagmcp = NULL;
-    as->mcp += (LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2;
+    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 = p;
+    }  /* else: cannot transform LE/NLE to cc without use of OF. */
   }
   right = IR(rref)->r;
   if (ra_hasreg(right)) {