]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
x86/x64: Fix register allocation for variable shifts.
authorMike Pall <mike>
Wed, 22 Jun 2011 18:38:07 +0000 (20:38 +0200)
committerMike Pall <mike>
Wed, 22 Jun 2011 18:38:07 +0000 (20:38 +0200)
src/lj_asm_x86.h

index ba28792dbcaa57f47680ec7892514b94ba3fde7f..da818c68ec13a830c3450f3b303a523364734b31 100644 (file)
@@ -1878,15 +1878,17 @@ static void asm_bitshift(ASMState *as, IRIns *ir, x86Shift xs)
     default: emit_shifti(as, REX_64IR(ir, xs), dest, shift); break;
     }
   } else {  /* Variable shifts implicitly use register cl (i.e. ecx). */
-    RegSet allow = rset_exclude(RSET_GPR, RID_ECX);
-    Reg right = irr->r;
-    if (ra_noreg(right)) {
+    Reg right;
+    dest = ra_dest(as, ir, rset_exclude(RSET_GPR, RID_ECX));
+    if (dest == RID_ECX) {
+      dest = ra_scratch(as, rset_exclude(RSET_GPR, RID_ECX));
+      emit_rr(as, XO_MOV, RID_ECX, dest);
+    }
+    right = irr->r;
+    if (ra_noreg(right))
       right = ra_allocref(as, rref, RID2RSET(RID_ECX));
-    } else if (right != RID_ECX) {
-      rset_clear(allow, right);
+    else if (right != RID_ECX)
       ra_scratch(as, RID2RSET(RID_ECX));
-    }
-    dest = ra_dest(as, ir, allow);
     emit_rr(as, XO_SHIFTcl, REX_64IR(ir, xs), dest);
     if (right != RID_ECX) {
       ra_noweak(as, right);