From: Richard Henderson Date: Mon, 2 Jun 2025 13:11:51 +0000 (+0100) Subject: tcg/optimize: Introduce fold_masks_zosa X-Git-Tag: v10.1.0-rc0~39^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e397cc0df9c642381e60f97ce37eafe5a2582b3;p=thirdparty%2Fqemu.git tcg/optimize: Introduce fold_masks_zosa Add a new function with an affected mask. This will allow folding to a constant to happen before folding to a copy, without having to mind the ordering in all users. Reviewed-by: Pierrick Bouvier Signed-off-by: Richard Henderson --- diff --git a/tcg/optimize.c b/tcg/optimize.c index ce3cb4d7bcf..49ef0399320 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -1039,8 +1039,8 @@ static bool fold_const2_commutative(OptContext *ctx, TCGOp *op) * If z_mask allows, fold the output to constant zero. * The passed s_mask may be augmented by z_mask. */ -static bool fold_masks_zos(OptContext *ctx, TCGOp *op, uint64_t z_mask, - uint64_t o_mask, int64_t s_mask) +static bool fold_masks_zosa(OptContext *ctx, TCGOp *op, uint64_t z_mask, + uint64_t o_mask, int64_t s_mask, uint64_t a_mask) { const TCGOpDef *def = &tcg_op_defs[op->opc]; TCGTemp *ts; @@ -1061,6 +1061,7 @@ static bool fold_masks_zos(OptContext *ctx, TCGOp *op, uint64_t z_mask, z_mask = (int32_t)z_mask; o_mask = (int32_t)o_mask; s_mask |= INT32_MIN; + a_mask = (uint32_t)a_mask; } /* Bits that are known 1 and bits that are known 0 must not overlap. */ @@ -1071,6 +1072,11 @@ static bool fold_masks_zos(OptContext *ctx, TCGOp *op, uint64_t z_mask, return tcg_opt_gen_movi(ctx, op, op->args[0], o_mask); } + /* If no bits are affected, the operation devolves to a copy. */ + if (a_mask == 0) { + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); + } + ts = arg_temp(op->args[0]); reset_ts(ctx, ts); @@ -1090,17 +1096,17 @@ static bool fold_masks_zos(OptContext *ctx, TCGOp *op, uint64_t z_mask, static bool fold_masks_zs(OptContext *ctx, TCGOp *op, uint64_t z_mask, uint64_t s_mask) { - return fold_masks_zos(ctx, op, z_mask, 0, s_mask); + return fold_masks_zosa(ctx, op, z_mask, 0, s_mask, -1); } static bool fold_masks_z(OptContext *ctx, TCGOp *op, uint64_t z_mask) { - return fold_masks_zos(ctx, op, z_mask, 0, 0); + return fold_masks_zosa(ctx, op, z_mask, 0, 0, -1); } static bool fold_masks_s(OptContext *ctx, TCGOp *op, uint64_t s_mask) { - return fold_masks_zos(ctx, op, -1, 0, s_mask); + return fold_masks_zosa(ctx, op, -1, 0, s_mask, -1); } /*