Add some more fold rules around integer conversions

1. u32 -> int -> u32 and int -> u32 -> int are no-ops
2. math.floor/math.ceil can be dropped if their argument is the result of _any_ conversion from integer
This commit is contained in:
Peter Cawley 2024-08-11 19:14:44 +01:00
parent 04dca7911e
commit 99d4926664

View File

@ -1170,8 +1170,10 @@ LJFOLDF(simplify_conv_i64_num)
LJFOLD(CONV CONV IRCONV_INT_I64) /* _INT or _U32 */ LJFOLD(CONV CONV IRCONV_INT_I64) /* _INT or _U32 */
LJFOLD(CONV CONV IRCONV_INT_U64) /* _INT or _U32 */ LJFOLD(CONV CONV IRCONV_INT_U64) /* _INT or _U32 */
LJFOLD(CONV CONV IRCONV_INT_U32) /* _INT or _U32 */
LJFOLD(CONV CONV IRCONV_U32_I64) /* _INT or _U32 */ LJFOLD(CONV CONV IRCONV_U32_I64) /* _INT or _U32 */
LJFOLD(CONV CONV IRCONV_U32_U64) /* _INT or _U32 */ LJFOLD(CONV CONV IRCONV_U32_U64) /* _INT or _U32 */
LJFOLD(CONV CONV IRCONV_U32_INT) /* _INT or _U32 */
LJFOLDF(simplify_conv_int_i64) LJFOLDF(simplify_conv_int_i64)
{ {
int src; int src;
@ -1216,14 +1218,13 @@ LJFOLDF(simplify_tobit_conv)
return NEXTFOLD; return NEXTFOLD;
} }
/* Shortcut floor/ceil/round + IRT_NUM <- IRT_INT/IRT_U32 conversion. */ /* Shortcut floor/ceil/trunc + IRT_NUM <- integer conversion. */
LJFOLD(FPMATH CONV IRFPM_FLOOR) LJFOLD(FPMATH CONV IRFPM_FLOOR)
LJFOLD(FPMATH CONV IRFPM_CEIL) LJFOLD(FPMATH CONV IRFPM_CEIL)
LJFOLD(FPMATH CONV IRFPM_TRUNC) LJFOLD(FPMATH CONV IRFPM_TRUNC)
LJFOLDF(simplify_floor_conv) LJFOLDF(simplify_floor_conv)
{ {
if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT || if ((uint32_t)(fleft->op2 & IRCONV_SRCMASK) - (uint32_t)IRT_I8 <= (uint32_t)(IRT_U64 - IRT_U8))
(fleft->op2 & IRCONV_SRCMASK) == IRT_U32)
return LEFTFOLD; return LEFTFOLD;
return NEXTFOLD; return NEXTFOLD;
} }