tcg/optimize: Use fold_masks_zs in fold_bswap

Avoid the use of the OptContext slots.  Find TempOptInfo once.
Always set s_mask along the BSWAP_OS path, since the result is
being explicitly sign-extended.

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2024-12-08 19:42:20 -06:00
parent 21e2b5f9fa
commit c1e7b989c8

View file

@ -1477,16 +1477,16 @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op)
static bool fold_bswap(OptContext *ctx, TCGOp *op) static bool fold_bswap(OptContext *ctx, TCGOp *op)
{ {
uint64_t z_mask, s_mask, sign; uint64_t z_mask, s_mask, sign;
TempOptInfo *t1 = arg_info(op->args[1]);
if (arg_is_const(op->args[1])) { if (ti_is_const(t1)) {
uint64_t t = arg_info(op->args[1])->val; return tcg_opt_gen_movi(ctx, op, op->args[0],
do_constant_folding(op->opc, ctx->type,
t = do_constant_folding(op->opc, ctx->type, t, op->args[2]); ti_const_val(t1),
return tcg_opt_gen_movi(ctx, op, op->args[0], t); op->args[2]));
} }
z_mask = arg_info(op->args[1])->z_mask; z_mask = t1->z_mask;
switch (op->opc) { switch (op->opc) {
case INDEX_op_bswap16_i32: case INDEX_op_bswap16_i32:
case INDEX_op_bswap16_i64: case INDEX_op_bswap16_i64:
@ -1514,18 +1514,17 @@ static bool fold_bswap(OptContext *ctx, TCGOp *op)
/* If the sign bit may be 1, force all the bits above to 1. */ /* If the sign bit may be 1, force all the bits above to 1. */
if (z_mask & sign) { if (z_mask & sign) {
z_mask |= sign; z_mask |= sign;
s_mask = sign << 1;
} }
/* The value and therefore s_mask is explicitly sign-extended. */
s_mask = sign;
break; break;
default: default:
/* The high bits are undefined: force all bits above the sign to 1. */ /* The high bits are undefined: force all bits above the sign to 1. */
z_mask |= sign << 1; z_mask |= sign << 1;
break; break;
} }
ctx->z_mask = z_mask;
ctx->s_mask = s_mask;
return fold_masks(ctx, op); return fold_masks_zs(ctx, op, z_mask, s_mask);
} }
static bool fold_call(OptContext *ctx, TCGOp *op) static bool fold_call(OptContext *ctx, TCGOp *op)