@samitouri / QOSamiQemu / commits / f7c62771e6

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>

Richard Henderson committed May 20, 2026 at 14:51 UTC f7c62771e6b88bd256d4b4ec71a53d5245f0fa8a
1 file changed +34 -34
tcg/optimize.c
+34 -34
@@ -2173,45 +2173,45 @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op)
2173 {
2174 swap_commutative(op->args[0], &op->args[2], &op->args[3]);
2175
2176 - if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) {
2177 - uint64_t a = arg_const_val(op->args[2]);
2176 + if (arg_is_const(op->args[3])) {
2177 uint64_t b = arg_const_val(op->args[3]);
2179 - uint64_t h, l;
2180 - TCGArg rl, rh;
2178 + TCGArg rl = op->args[0];
2179 + TCGArg rh = op->args[1];
2180 TCGOp *op2;
2181
2183 - switch (op->opc) {
2184 - case INDEX_op_mulu2:
2185 - if (ctx->type == TCG_TYPE_I32) {
2186 - l = (uint64_t)(uint32_t)a * (uint32_t)b;
2187 - h = (int32_t)(l >> 32);
2188 - l = (int32_t)l;
2189 - } else {
2190 - mulu64(&l, &h, a, b);
2191 - }
2192 - break;
2193 - case INDEX_op_muls2:
2194 - if (ctx->type == TCG_TYPE_I32) {
2195 - l = (int64_t)(int32_t)a * (int32_t)b;
2196 - h = l >> 32;
2197 - l = (int32_t)l;
2198 - } else {
2199 - muls64(&l, &h, a, b);
2182 + if (arg_is_const(op->args[2])) {
2183 + uint64_t a = arg_const_val(op->args[2]);
2184 + uint64_t h, l;
2185 +
2186 + switch (op->opc) {
2187 + case INDEX_op_mulu2:
2188 + if (ctx->type == TCG_TYPE_I32) {
2189 + l = (uint64_t)(uint32_t)a * (uint32_t)b;
2190 + h = (int32_t)(l >> 32);
2191 + l = (int32_t)l;
2192 + } else {
2193 + mulu64(&l, &h, a, b);
2194 + }
2195 + break;
2196 + case INDEX_op_muls2:
2197 + if (ctx->type == TCG_TYPE_I32) {
2198 + l = (int64_t)(int32_t)a * (int32_t)b;
2199 + h = l >> 32;
2200 + l = (int32_t)l;
2201 + } else {
2202 + muls64(&l, &h, a, b);
2203 + }
2204 + break;
2205 + default:
2206 + g_assert_not_reached();
2207 }
2201 - break;
2202 - default:
2203 - g_assert_not_reached();
2204 - }
2205 -
2206 - rl = op->args[0];
2207 - rh = op->args[1];
2208
2209 - /* The proper opcode is supplied by tcg_opt_gen_mov. */
2210 - op2 = opt_insert_before(ctx, op, 0, 2);
2211 -
2212 - tcg_opt_gen_movi(ctx, op, rl, l);
2213 - tcg_opt_gen_movi(ctx, op2, rh, h);
2214 - return true;
2209 + /* The proper opcode is supplied by tcg_opt_gen_mov. */
2210 + op2 = opt_insert_before(ctx, op, 0, 2);
2211 + tcg_opt_gen_movi(ctx, op, rl, l);
2212 + tcg_opt_gen_movi(ctx, op2, rh, h);
2213 + return true;
2214 + }
2215 }
2216 return finish_folding(ctx, op);
2217 }