tcg/optimize: Split out fold_addsub2_i32

Add two additional helpers, fold_add2_i32 and fold_sub2_i32
which will not be simple wrappers forever.

Reviewed-by: Luis Pires <luis.pires@eldorado.org.br>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2021-08-24 10:30:38 -07:00
parent 6b8ac0d149
commit e3f7dc2167
1 changed files with 44 additions and 26 deletions

View File

@ -704,6 +704,39 @@ static bool fold_add(OptContext *ctx, TCGOp *op)
return fold_const2(ctx, op);
}
static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add)
{
if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) &&
arg_is_const(op->args[4]) && arg_is_const(op->args[5])) {
uint32_t al = arg_info(op->args[2])->val;
uint32_t ah = arg_info(op->args[3])->val;
uint32_t bl = arg_info(op->args[4])->val;
uint32_t bh = arg_info(op->args[5])->val;
uint64_t a = ((uint64_t)ah << 32) | al;
uint64_t b = ((uint64_t)bh << 32) | bl;
TCGArg rl, rh;
TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32);
if (add) {
a += b;
} else {
a -= b;
}
rl = op->args[0];
rh = op->args[1];
tcg_opt_gen_movi(ctx, op, rl, (int32_t)a);
tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(a >> 32));
return true;
}
return false;
}
static bool fold_add2_i32(OptContext *ctx, TCGOp *op)
{
return fold_addsub2_i32(ctx, op, true);
}
static bool fold_and(OptContext *ctx, TCGOp *op)
{
return fold_const2(ctx, op);
@ -1056,6 +1089,11 @@ static bool fold_sub(OptContext *ctx, TCGOp *op)
return fold_const2(ctx, op);
}
static bool fold_sub2_i32(OptContext *ctx, TCGOp *op)
{
return fold_addsub2_i32(ctx, op, false);
}
static bool fold_xor(OptContext *ctx, TCGOp *op)
{
return fold_const2(ctx, op);
@ -1701,32 +1739,6 @@ void tcg_optimize(TCGContext *s)
}
break;
case INDEX_op_add2_i32:
case INDEX_op_sub2_i32:
if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])
&& arg_is_const(op->args[4]) && arg_is_const(op->args[5])) {
uint32_t al = arg_info(op->args[2])->val;
uint32_t ah = arg_info(op->args[3])->val;
uint32_t bl = arg_info(op->args[4])->val;
uint32_t bh = arg_info(op->args[5])->val;
uint64_t a = ((uint64_t)ah << 32) | al;
uint64_t b = ((uint64_t)bh << 32) | bl;
TCGArg rl, rh;
TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_mov_i32);
if (opc == INDEX_op_add2_i32) {
a += b;
} else {
a -= b;
}
rl = op->args[0];
rh = op->args[1];
tcg_opt_gen_movi(&ctx, op, rl, (int32_t)a);
tcg_opt_gen_movi(&ctx, op2, rh, (int32_t)(a >> 32));
continue;
}
break;
default:
break;
@ -1737,6 +1749,9 @@ void tcg_optimize(TCGContext *s)
CASE_OP_32_64_VEC(add):
done = fold_add(&ctx, op);
break;
case INDEX_op_add2_i32:
done = fold_add2_i32(&ctx, op);
break;
CASE_OP_32_64_VEC(and):
done = fold_and(&ctx, op);
break;
@ -1833,6 +1848,9 @@ void tcg_optimize(TCGContext *s)
CASE_OP_32_64_VEC(sub):
done = fold_sub(&ctx, op);
break;
case INDEX_op_sub2_i32:
done = fold_sub2_i32(&ctx, op);
break;
CASE_OP_32_64_VEC(xor):
done = fold_xor(&ctx, op);
break;