]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
ARM: Fix condition code check fusion.
authorMike Pall <mike>
Mon, 29 Apr 2019 15:38:05 +0000 (17:38 +0200)
committerMike Pall <mike>
Mon, 29 Apr 2019 15:38:05 +0000 (17:38 +0200)
Reported by Qingjun Wei.

src/lj_asm_arm.h

index 961f7e3972278c09e83315e9bb2bc0dceeb54d09..8e0ebd7a6001ebaa74320177bd760ac7f2d5ac96 100644 (file)
@@ -1449,19 +1449,10 @@ static void asm_intop(ASMState *as, IRIns *ir, ARMIns ai)
   emit_dn(as, ai^m, dest, left);
 }
 
-static void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai)
-{
-  if (as->flagmcp == as->mcp) {  /* Drop cmp r, #0. */
-    as->flagmcp = NULL;
-    as->mcp++;
-    ai |= ARMI_S;
-  }
-  asm_intop(as, ir, ai);
-}
-
-static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai)
+/* Try to drop cmp r, #0. */
+static ARMIns asm_drop_cmp0(ASMState *as, ARMIns ai)
 {
-  if (as->flagmcp == as->mcp) {  /* Try to drop cmp r, #0. */
+  if (as->flagmcp == as->mcp) {
     uint32_t cc = (as->mcp[1] >> 28);
     as->flagmcp = NULL;
     if (cc <= CC_NE) {
@@ -1473,8 +1464,19 @@ static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai)
     } else if (cc == CC_LT) {
       *++as->mcp ^= ((CC_LT^CC_MI) << 28);
       ai |= ARMI_S;
-    }  /* else: other conds don't work with bit ops. */
+    }  /* else: other conds don't work in general. */
   }
+  return ai;
+}
+
+static void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai)
+{
+  asm_intop(as, ir, asm_drop_cmp0(as, ai));
+}
+
+static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai)
+{
+  ai = asm_drop_cmp0(as, ai);
   if (ir->op2 == 0) {
     Reg dest = ra_dest(as, ir, RSET_GPR);
     uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR);