Commit f7c62771e6 for qemu.org
commit f7c62771e6b88bd256d4b4ec71a53d5245f0fa8a
Author: Richard Henderson <richard.henderson@linaro.org>
Date: Wed May 20 14:51:38 2026 +0200
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>
diff --git a/tcg/optimize.c b/tcg/optimize.c
index b1abec69a5..ef5eb2cf17 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -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);
- }
- 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);
+ 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;
- default:
- g_assert_not_reached();
- }
-
- 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;
+ /* 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);
}