diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_opt_fold.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index fc625b84..94d5702f 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
@@ -596,18 +596,13 @@ LJFOLDF(bufstr_kfold_cse) | |||
596 | if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { | 596 | if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) { |
597 | IRRef ref = J->chain[IR_BUFSTR]; | 597 | IRRef ref = J->chain[IR_BUFSTR]; |
598 | while (ref) { | 598 | while (ref) { |
599 | IRRef last = fins->op1; | ||
600 | IRIns *irs = IR(ref), *ira = fleft, *irb = IR(irs->op1); | 599 | IRIns *irs = IR(ref), *ira = fleft, *irb = IR(irs->op1); |
601 | while (ira->o == irb->o && ira->op2 == irb->op2) { | 600 | while (ira->o == irb->o && ira->op2 == irb->op2) { |
602 | if (ira->o == IR_BUFHDR && !(ira->op2 & IRBUFHDR_APPEND)) { | 601 | lua_assert(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT || |
602 | ira->o == IR_CALLL || ira->o == IR_CARG); | ||
603 | if (ira->o == IR_BUFHDR && !(ira->op2 & IRBUFHDR_APPEND)) | ||
603 | return ref; /* CSE succeeded. */ | 604 | return ref; /* CSE succeeded. */ |
604 | } else if (ira->o == IR_CALLL) { | 605 | ira = IR(ira->op1); |
605 | ira = IR(ira->op1); irb = IR(irb->op1); | ||
606 | lua_assert(ira->o == IR_CARG && irb->o == IR_CARG); | ||
607 | if (ira->op2 != irb->op2) break; | ||
608 | } | ||
609 | last = ira->op1; | ||
610 | ira = IR(last); | ||
611 | irb = IR(irb->op1); | 606 | irb = IR(irb->op1); |
612 | } | 607 | } |
613 | ref = irs->prev; | 608 | ref = irs->prev; |
@@ -623,17 +618,32 @@ LJFOLDF(bufput_kfold_op) | |||
623 | { | 618 | { |
624 | if (irref_isk(fleft->op2)) { | 619 | if (irref_isk(fleft->op2)) { |
625 | const CCallInfo *ci = &lj_ir_callinfo[fins->op2]; | 620 | const CCallInfo *ci = &lj_ir_callinfo[fins->op2]; |
626 | SBuf *sb = &J2G(J)->tmpbuf; | 621 | SBuf *sb = lj_buf_tmp_(J->L); |
627 | setsbufL(sb, J->L); | ||
628 | lj_buf_reset(sb); | ||
629 | sb = ((SBuf * (LJ_FASTCALL *)(SBuf *, GCstr *))ci->func)(sb, | 622 | sb = ((SBuf * (LJ_FASTCALL *)(SBuf *, GCstr *))ci->func)(sb, |
630 | ir_kstr(IR(fleft->op2))); | 623 | ir_kstr(IR(fleft->op2))); |
631 | fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb)); | ||
632 | fins->op1 = fleft->op1; | ||
633 | fins->o = IR_BUFPUT; | 624 | fins->o = IR_BUFPUT; |
625 | fins->op1 = fleft->op1; | ||
626 | fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb)); | ||
634 | return RETRYFOLD; | 627 | return RETRYFOLD; |
635 | } | 628 | } |
636 | return EMITFOLD; /* This is a store and always emitted. */ | 629 | return EMITFOLD; /* Always emit, CSE later. */ |
630 | } | ||
631 | |||
632 | LJFOLD(CALLL CARG IRCALL_lj_buf_putstr_rep) | ||
633 | LJFOLDF(bufput_kfold_rep) | ||
634 | { | ||
635 | if (irref_isk(fleft->op2)) { | ||
636 | IRIns *irc = IR(fleft->op1); | ||
637 | if (irref_isk(irc->op2)) { | ||
638 | SBuf *sb = lj_buf_tmp_(J->L); | ||
639 | sb = lj_buf_putstr_rep(sb, ir_kstr(IR(irc->op2)), IR(fleft->op2)->i); | ||
640 | fins->o = IR_BUFPUT; | ||
641 | fins->op1 = irc->op1; | ||
642 | fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb)); | ||
643 | return RETRYFOLD; | ||
644 | } | ||
645 | } | ||
646 | return EMITFOLD; /* Always emit, CSE later. */ | ||
637 | } | 647 | } |
638 | 648 | ||
639 | /* -- Constant folding of pointer arithmetic ------------------------------ */ | 649 | /* -- Constant folding of pointer arithmetic ------------------------------ */ |