diff options
Diffstat (limited to 'src/lj_opt_fold.c')
-rw-r--r-- | src/lj_opt_fold.c | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index e67f3ee6..75db47df 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
@@ -22,8 +22,8 @@ | |||
22 | #include "lj_trace.h" | 22 | #include "lj_trace.h" |
23 | #if LJ_HASFFI | 23 | #if LJ_HASFFI |
24 | #include "lj_ctype.h" | 24 | #include "lj_ctype.h" |
25 | #endif | ||
26 | #include "lj_carith.h" | 25 | #include "lj_carith.h" |
26 | #endif | ||
27 | #include "lj_vm.h" | 27 | #include "lj_vm.h" |
28 | #include "lj_strscan.h" | 28 | #include "lj_strscan.h" |
29 | 29 | ||
@@ -336,11 +336,9 @@ LJFOLDF(kfold_intcomp0) | |||
336 | static uint64_t kfold_int64arith(uint64_t k1, uint64_t k2, IROp op) | 336 | static uint64_t kfold_int64arith(uint64_t k1, uint64_t k2, IROp op) |
337 | { | 337 | { |
338 | switch (op) { | 338 | switch (op) { |
339 | #if LJ_64 || LJ_HASFFI | 339 | #if LJ_HASFFI |
340 | case IR_ADD: k1 += k2; break; | 340 | case IR_ADD: k1 += k2; break; |
341 | case IR_SUB: k1 -= k2; break; | 341 | case IR_SUB: k1 -= k2; break; |
342 | #endif | ||
343 | #if LJ_HASFFI | ||
344 | case IR_MUL: k1 *= k2; break; | 342 | case IR_MUL: k1 *= k2; break; |
345 | case IR_BAND: k1 &= k2; break; | 343 | case IR_BAND: k1 &= k2; break; |
346 | case IR_BOR: k1 |= k2; break; | 344 | case IR_BOR: k1 |= k2; break; |
@@ -392,20 +390,10 @@ LJFOLD(BROL KINT64 KINT) | |||
392 | LJFOLD(BROR KINT64 KINT) | 390 | LJFOLD(BROR KINT64 KINT) |
393 | LJFOLDF(kfold_int64shift) | 391 | LJFOLDF(kfold_int64shift) |
394 | { | 392 | { |
395 | #if LJ_HASFFI || LJ_64 | 393 | #if LJ_HASFFI |
396 | uint64_t k = ir_k64(fleft)->u64; | 394 | uint64_t k = ir_k64(fleft)->u64; |
397 | int32_t sh = (fright->i & 63); | 395 | int32_t sh = (fright->i & 63); |
398 | switch ((IROp)fins->o) { | 396 | return INT64FOLD(lj_carith_shift64(k, sh, fins->o - IR_BSHL)); |
399 | case IR_BSHL: k <<= sh; break; | ||
400 | #if LJ_HASFFI | ||
401 | case IR_BSHR: k >>= sh; break; | ||
402 | case IR_BSAR: k = (uint64_t)((int64_t)k >> sh); break; | ||
403 | case IR_BROL: k = lj_rol(k, sh); break; | ||
404 | case IR_BROR: k = lj_ror(k, sh); break; | ||
405 | #endif | ||
406 | default: lua_assert(0); break; | ||
407 | } | ||
408 | return INT64FOLD(k); | ||
409 | #else | 397 | #else |
410 | UNUSED(J); lua_assert(0); return FAILFOLD; | 398 | UNUSED(J); lua_assert(0); return FAILFOLD; |
411 | #endif | 399 | #endif |
@@ -1192,7 +1180,9 @@ static TRef simplify_intmul_k(jit_State *J, int32_t k) | |||
1192 | ** But this is mainly intended for simple address arithmetic. | 1180 | ** But this is mainly intended for simple address arithmetic. |
1193 | ** Also it's easier for the backend to optimize the original multiplies. | 1181 | ** Also it's easier for the backend to optimize the original multiplies. |
1194 | */ | 1182 | */ |
1195 | if (k == 1) { /* i * 1 ==> i */ | 1183 | if (k == 0) { /* i * 0 ==> 0 */ |
1184 | return RIGHTFOLD; | ||
1185 | } else if (k == 1) { /* i * 1 ==> i */ | ||
1196 | return LEFTFOLD; | 1186 | return LEFTFOLD; |
1197 | } else if ((k & (k-1)) == 0) { /* i * 2^k ==> i << k */ | 1187 | } else if ((k & (k-1)) == 0) { /* i * 2^k ==> i << k */ |
1198 | fins->o = IR_BSHL; | 1188 | fins->o = IR_BSHL; |
@@ -1205,9 +1195,7 @@ static TRef simplify_intmul_k(jit_State *J, int32_t k) | |||
1205 | LJFOLD(MUL any KINT) | 1195 | LJFOLD(MUL any KINT) |
1206 | LJFOLDF(simplify_intmul_k32) | 1196 | LJFOLDF(simplify_intmul_k32) |
1207 | { | 1197 | { |
1208 | if (fright->i == 0) /* i * 0 ==> 0 */ | 1198 | if (fright->i >= 0) |
1209 | return INTFOLD(0); | ||
1210 | else if (fright->i > 0) | ||
1211 | return simplify_intmul_k(J, fright->i); | 1199 | return simplify_intmul_k(J, fright->i); |
1212 | return NEXTFOLD; | 1200 | return NEXTFOLD; |
1213 | } | 1201 | } |
@@ -1215,14 +1203,13 @@ LJFOLDF(simplify_intmul_k32) | |||
1215 | LJFOLD(MUL any KINT64) | 1203 | LJFOLD(MUL any KINT64) |
1216 | LJFOLDF(simplify_intmul_k64) | 1204 | LJFOLDF(simplify_intmul_k64) |
1217 | { | 1205 | { |
1218 | if (ir_kint64(fright)->u64 == 0) /* i * 0 ==> 0 */ | 1206 | #if LJ_HASFFI |
1219 | return INT64FOLD(0); | 1207 | if (ir_kint64(fright)->u64 < 0x80000000u) |
1220 | #if LJ_64 | ||
1221 | /* NYI: SPLIT for BSHL and 32 bit backend support. */ | ||
1222 | else if (ir_kint64(fright)->u64 < 0x80000000u) | ||
1223 | return simplify_intmul_k(J, (int32_t)ir_kint64(fright)->u64); | 1208 | return simplify_intmul_k(J, (int32_t)ir_kint64(fright)->u64); |
1224 | #endif | ||
1225 | return NEXTFOLD; | 1209 | return NEXTFOLD; |
1210 | #else | ||
1211 | UNUSED(J); lua_assert(0); return FAILFOLD; | ||
1212 | #endif | ||
1226 | } | 1213 | } |
1227 | 1214 | ||
1228 | LJFOLD(MOD any KINT) | 1215 | LJFOLD(MOD any KINT) |
@@ -1522,7 +1509,7 @@ LJFOLD(BOR BOR KINT64) | |||
1522 | LJFOLD(BXOR BXOR KINT64) | 1509 | LJFOLD(BXOR BXOR KINT64) |
1523 | LJFOLDF(reassoc_intarith_k64) | 1510 | LJFOLDF(reassoc_intarith_k64) |
1524 | { | 1511 | { |
1525 | #if LJ_HASFFI || LJ_64 | 1512 | #if LJ_HASFFI |
1526 | IRIns *irk = IR(fleft->op2); | 1513 | IRIns *irk = IR(fleft->op2); |
1527 | if (irk->o == IR_KINT64) { | 1514 | if (irk->o == IR_KINT64) { |
1528 | uint64_t k = kfold_int64arith(ir_k64(irk)->u64, | 1515 | uint64_t k = kfold_int64arith(ir_k64(irk)->u64, |