mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
tcg: Optimize INDEX_op_mul[us]2 for 0 and 1
Zero operands produce a zero high and low product. One operands produce a copy of the other operand and a zero or sign extension in the high half. Fold those cases during TCG optimization so wide-multiply idioms used by target translators can collapse before code generation. Signed-off-by: James Hilliard <james.hilliard1@gmail.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260520125139.13352-3-philmd@linaro.org>
This commit is contained in:
@@ -2212,6 +2212,34 @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op)
|
||||
tcg_opt_gen_movi(ctx, op2, rh, h);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (b == 0) {
|
||||
op2 = opt_insert_before(ctx, op, 0, 2);
|
||||
tcg_opt_gen_movi(ctx, op2, rl, 0);
|
||||
tcg_opt_gen_movi(ctx, op, rh, 0);
|
||||
return true;
|
||||
}
|
||||
if (b == 1) {
|
||||
op2 = opt_insert_before(ctx, op, 0, 2);
|
||||
tcg_opt_gen_mov(ctx, op2, rl, op->args[2]);
|
||||
|
||||
switch (op->opc) {
|
||||
case INDEX_op_mulu2:
|
||||
tcg_opt_gen_movi(ctx, op, rh, 0);
|
||||
break;
|
||||
case INDEX_op_muls2:
|
||||
op->opc = INDEX_op_sar;
|
||||
op->args[0] = rh;
|
||||
op->args[1] = rl;
|
||||
op->args[2] =
|
||||
arg_new_constant(ctx, tcg_type_size(ctx->type) * 8 - 1);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return finish_folding(ctx, op);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user