diff --git a/src/lj_asm.c b/src/lj_asm.c index ebcff43c..9dae2707 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c @@ -1149,24 +1149,30 @@ static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode); static void asm_bufhdr(ASMState *as, IRIns *ir) { Reg sb = ra_dest(as, ir, RSET_GPR); - if ((ir->op2 & IRBUFHDR_APPEND)) { + switch (ir->op2) { + case IRBUFHDR_RESET: { + Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); + IRIns irbp; + irbp.ot = IRT(0, IRT_PTR); /* Buffer data pointer type. */ + emit_storeofs(as, &irbp, tmp, sb, offsetof(SBuf, w)); + emit_loadofs(as, &irbp, tmp, sb, offsetof(SBuf, b)); + break; + } + case IRBUFHDR_APPEND: { /* Rematerialize const buffer pointer instead of likely spill. */ IRIns *irp = IR(ir->op1); if (!(ra_hasreg(irp->r) || irp == ir-1 || (irp == ir-2 && !ra_used(ir-1)))) { - while (!(irp->o == IR_BUFHDR && !(irp->op2 & IRBUFHDR_APPEND))) + while (!(irp->o == IR_BUFHDR && irp->op2 == IRBUFHDR_RESET)) irp = IR(irp->op1); if (irref_isk(irp->op1)) { ra_weak(as, ra_allocref(as, ir->op1, RSET_GPR)); ir = irp; } } - } else { - Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); - IRIns irbp; - irbp.ot = IRT(0, IRT_PTR); /* Buffer data pointer type. */ - emit_storeofs(as, &irbp, tmp, sb, offsetof(SBuf, w)); - emit_loadofs(as, &irbp, tmp, sb, offsetof(SBuf, b)); + break; + } + default: lj_assertA(0, "bad BUFHDR op2 %d", ir->op2); break; } #if LJ_TARGET_X86ORX64 ra_left(as, sb, ir->op1); diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index 9a41a5a4..06731c7a 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c @@ -586,11 +586,11 @@ LJFOLDF(bufput_append) { /* New buffer, no other buffer op inbetween and same buffer? */ if ((J->flags & JIT_F_OPT_FWD) && - !(fleft->op2 & IRBUFHDR_APPEND) && + fleft->op2 == IRBUFHDR_RESET && fleft->prev == fright->op2 && fleft->op1 == IR(fright->op2)->op1) { IRRef ref = fins->op1; - IR(ref)->op2 = (fleft->op2 | IRBUFHDR_APPEND); /* Modify BUFHDR. */ + IR(ref)->op2 = IRBUFHDR_APPEND; /* Modify BUFHDR. */ IR(ref)->op1 = fright->op1; return ref; } @@ -626,14 +626,14 @@ LJFOLDF(bufstr_kfold_cse) "bad buffer constructor IR op %d", fleft->o); if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { if (fleft->o == IR_BUFHDR) { /* No put operations? */ - if (!(fleft->op2 & IRBUFHDR_APPEND)) /* Empty buffer? */ + if (fleft->op2 == IRBUFHDR_RESET) /* Empty buffer? */ return lj_ir_kstr(J, &J2G(J)->strempty); fins->op1 = fleft->op1; fins->op2 = fleft->prev; /* Relies on checks in bufput_append. */ return CSEFOLD; } else if (fleft->o == IR_BUFPUT) { IRIns *irb = IR(fleft->op1); - if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND)) + if (irb->o == IR_BUFHDR && irb->op2 == IRBUFHDR_RESET) return fleft->op2; /* Shortcut for a single put operation. */ } } @@ -646,7 +646,7 @@ LJFOLDF(bufstr_kfold_cse) lj_assertJ(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT || ira->o == IR_CALLL || ira->o == IR_CARG, "bad buffer constructor IR op %d", ira->o); - if (ira->o == IR_BUFHDR && !(ira->op2 & IRBUFHDR_APPEND)) + if (ira->o == IR_BUFHDR && ira->op2 == IRBUFHDR_RESET) return ref; /* CSE succeeded. */ if (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab) break;