tcg/optimize: Split out fold_extract2

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:41:39 -07:00
parent 0c310a3005
commit dcd08996c9
1 changed files with 22 additions and 17 deletions

View File

@ -888,6 +888,25 @@ static bool fold_eqv(OptContext *ctx, TCGOp *op)
return fold_const2(ctx, op);
}
static bool fold_extract2(OptContext *ctx, TCGOp *op)
{
if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) {
uint64_t v1 = arg_info(op->args[1])->val;
uint64_t v2 = arg_info(op->args[2])->val;
int shr = op->args[3];
if (op->opc == INDEX_op_extract2_i64) {
v1 >>= shr;
v2 <<= 64 - shr;
} else {
v1 = (uint32_t)v1 >> shr;
v2 = (int32_t)v2 << (32 - shr);
}
return tcg_opt_gen_movi(ctx, op, op->args[0], v1 | v2);
}
return false;
}
static bool fold_exts(OptContext *ctx, TCGOp *op)
{
return fold_const1(ctx, op);
@ -1726,23 +1745,6 @@ void tcg_optimize(TCGContext *s)
}
break;
CASE_OP_32_64(extract2):
if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) {
uint64_t v1 = arg_info(op->args[1])->val;
uint64_t v2 = arg_info(op->args[2])->val;
int shr = op->args[3];
if (opc == INDEX_op_extract2_i64) {
tmp = (v1 >> shr) | (v2 << (64 - shr));
} else {
tmp = (int32_t)(((uint32_t)v1 >> shr) |
((uint32_t)v2 << (32 - shr)));
}
tcg_opt_gen_movi(&ctx, op, op->args[0], tmp);
continue;
}
break;
default:
break;
@ -1777,6 +1779,9 @@ void tcg_optimize(TCGContext *s)
CASE_OP_32_64(eqv):
done = fold_eqv(&ctx, op);
break;
CASE_OP_32_64(extract2):
done = fold_extract2(&ctx, op);
break;
CASE_OP_32_64(ext8s):
CASE_OP_32_64(ext16s):
case INDEX_op_ext32s_i64: