summaryrefslogtreecommitdiff
path: root/src/lj_opt_fold.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_opt_fold.c')
-rw-r--r--src/lj_opt_fold.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c
index feddba87..cf5de82f 100644
--- a/src/lj_opt_fold.c
+++ b/src/lj_opt_fold.c
@@ -270,6 +270,23 @@ LJFOLDF(kfold_toint)
270 return INTFOLD(k); 270 return INTFOLD(k);
271} 271}
272 272
273LJFOLD(TOI64 KINT any)
274LJFOLDF(kfold_toi64_kint)
275{
276 lua_assert(fins->op2 == IRTOINT_ZEXT64 || fins->op2 == IRTOINT_SEXT64);
277 if (fins->op2 == IRTOINT_ZEXT64)
278 return lj_ir_kint64(J, (int64_t)(uint32_t)fleft->i);
279 else
280 return lj_ir_kint64(J, (int64_t)(int32_t)fleft->i);
281}
282
283LJFOLD(TOI64 KNUM any)
284LJFOLDF(kfold_toi64_knum)
285{
286 lua_assert(fins->op2 == IRTOINT_TRUNCI64);
287 return lj_ir_kint64(J, (int64_t)knumleft);
288}
289
273LJFOLD(TOSTR KNUM) 290LJFOLD(TOSTR KNUM)
274LJFOLDF(kfold_tostr_knum) 291LJFOLDF(kfold_tostr_knum)
275{ 292{
@@ -471,6 +488,15 @@ LJFOLDF(shortcut_leftleft_across_phi)
471 return fleft->op1; /* f(g(x)) ==> x */ 488 return fleft->op1; /* f(g(x)) ==> x */
472} 489}
473 490
491LJFOLD(TOI64 TONUM any)
492LJFOLDF(shortcut_leftleft_toint64)
493{
494 /* Fold even across PHI to avoid expensive int->num->int64 conversions. */
495 fins->op1 = fleft->op1; /* (int64_t)(double)(int)x ==> (int64_t)x */
496 fins->op2 = IRTOINT_SEXT64;
497 return RETRYFOLD;
498}
499
474/* -- FP algebraic simplifications ---------------------------------------- */ 500/* -- FP algebraic simplifications ---------------------------------------- */
475 501
476/* FP arithmetic is tricky -- there's not much to simplify. 502/* FP arithmetic is tricky -- there's not much to simplify.