tcg: Massage fold_multiply2()

In order to ease next commit review, check arg2 constness
in the inner loop.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20260520125139.13352-2-philmd@linaro.org>
This commit is contained in:
Richard Henderson
2026-05-20 14:51:38 +02:00
parent faf1bfdd63
commit f7c62771e6

View File

@@ -2173,45 +2173,45 @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op)
{
swap_commutative(op->args[0], &op->args[2], &op->args[3]);
if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) {
uint64_t a = arg_const_val(op->args[2]);
if (arg_is_const(op->args[3])) {
uint64_t b = arg_const_val(op->args[3]);
uint64_t h, l;
TCGArg rl, rh;
TCGArg rl = op->args[0];
TCGArg rh = op->args[1];
TCGOp *op2;
switch (op->opc) {
case INDEX_op_mulu2:
if (ctx->type == TCG_TYPE_I32) {
l = (uint64_t)(uint32_t)a * (uint32_t)b;
h = (int32_t)(l >> 32);
l = (int32_t)l;
} else {
mulu64(&l, &h, a, b);
if (arg_is_const(op->args[2])) {
uint64_t a = arg_const_val(op->args[2]);
uint64_t h, l;
switch (op->opc) {
case INDEX_op_mulu2:
if (ctx->type == TCG_TYPE_I32) {
l = (uint64_t)(uint32_t)a * (uint32_t)b;
h = (int32_t)(l >> 32);
l = (int32_t)l;
} else {
mulu64(&l, &h, a, b);
}
break;
case INDEX_op_muls2:
if (ctx->type == TCG_TYPE_I32) {
l = (int64_t)(int32_t)a * (int32_t)b;
h = l >> 32;
l = (int32_t)l;
} else {
muls64(&l, &h, a, b);
}
break;
default:
g_assert_not_reached();
}
break;
case INDEX_op_muls2:
if (ctx->type == TCG_TYPE_I32) {
l = (int64_t)(int32_t)a * (int32_t)b;
h = l >> 32;
l = (int32_t)l;
} else {
muls64(&l, &h, a, b);
}
break;
default:
g_assert_not_reached();
/* The proper opcode is supplied by tcg_opt_gen_mov. */
op2 = opt_insert_before(ctx, op, 0, 2);
tcg_opt_gen_movi(ctx, op, rl, l);
tcg_opt_gen_movi(ctx, op2, rh, h);
return true;
}
rl = op->args[0];
rh = op->args[1];
/* The proper opcode is supplied by tcg_opt_gen_mov. */
op2 = opt_insert_before(ctx, op, 0, 2);
tcg_opt_gen_movi(ctx, op, rl, l);
tcg_opt_gen_movi(ctx, op2, rh, h);
return true;
}
return finish_folding(ctx, op);
}