[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 37/56] tcg/optimize: Split out fold_xi_to_i
From: |
Richard Henderson |
Subject: |
[PULL 37/56] tcg/optimize: Split out fold_xi_to_i |
Date: |
Wed, 27 Oct 2021 19:41:12 -0700 |
Pull the "op r, a, 0 => movi r, 0" optimization into a function,
and use it in the outer opcode fold functions.
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>
---
tcg/optimize.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index ab96849edf..cfdc53c964 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -695,6 +695,15 @@ static bool fold_const2(OptContext *ctx, TCGOp *op)
return false;
}
+/* If the binary operation has second argument @i, fold to @i. */
+static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i)
+{
+ if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == i) {
+ return tcg_opt_gen_movi(ctx, op, op->args[0], i);
+ }
+ return false;
+}
+
/* If the binary operation has both arguments equal, fold to @i. */
static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i)
{
@@ -763,6 +772,7 @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op)
static bool fold_and(OptContext *ctx, TCGOp *op)
{
if (fold_const2(ctx, op) ||
+ fold_xi_to_i(ctx, op, 0) ||
fold_xx_to_x(ctx, op)) {
return true;
}
@@ -1081,12 +1091,20 @@ static bool fold_movcond(OptContext *ctx, TCGOp *op)
static bool fold_mul(OptContext *ctx, TCGOp *op)
{
- return fold_const2(ctx, op);
+ if (fold_const2(ctx, op) ||
+ fold_xi_to_i(ctx, op, 0)) {
+ return true;
+ }
+ return false;
}
static bool fold_mul_highpart(OptContext *ctx, TCGOp *op)
{
- return fold_const2(ctx, op);
+ if (fold_const2(ctx, op) ||
+ fold_xi_to_i(ctx, op, 0)) {
+ return true;
+ }
+ return false;
}
static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op)
@@ -1753,22 +1771,6 @@ void tcg_optimize(TCGContext *s)
continue;
}
- /* Simplify expression for "op r, a, 0 => movi r, 0" cases */
- switch (opc) {
- CASE_OP_32_64_VEC(and):
- CASE_OP_32_64_VEC(mul):
- CASE_OP_32_64(muluh):
- CASE_OP_32_64(mulsh):
- if (arg_is_const(op->args[2])
- && arg_info(op->args[2])->val == 0) {
- tcg_opt_gen_movi(&ctx, op, op->args[0], 0);
- continue;
- }
- break;
- default:
- break;
- }
-
/*
* Process each opcode.
* Sorted alphabetically by opcode as much as possible.
--
2.25.1
- [PULL 35/56] tcg/optimize: Split out fold_xx_to_i, (continued)
- [PULL 35/56] tcg/optimize: Split out fold_xx_to_i, Richard Henderson, 2021/10/27
- [PULL 24/56] tcg/optimize: Split out fold_setcond, Richard Henderson, 2021/10/27
- [PULL 30/56] tcg/optimize: Split out fold_deposit, Richard Henderson, 2021/10/27
- [PULL 34/56] tcg/optimize: Split out fold_mov, Richard Henderson, 2021/10/27
- [PULL 28/56] tcg/optimize: Split out fold_extract2, Richard Henderson, 2021/10/27
- [PULL 39/56] tcg/optimize: Split out fold_to_not, Richard Henderson, 2021/10/27
- [PULL 08/56] tcg/optimize: Remove do_default label, Richard Henderson, 2021/10/27
- [PULL 22/56] tcg/optimize: Split out fold_brcond2, Richard Henderson, 2021/10/27
- [PULL 26/56] tcg/optimize: Split out fold_addsub2_i32, Richard Henderson, 2021/10/27
- [PULL 32/56] tcg/optimize: Split out fold_bswap, Richard Henderson, 2021/10/27
- [PULL 37/56] tcg/optimize: Split out fold_xi_to_i,
Richard Henderson <=
- [PULL 40/56] tcg/optimize: Split out fold_sub_to_neg, Richard Henderson, 2021/10/27
- [PULL 41/56] tcg/optimize: Split out fold_xi_to_x, Richard Henderson, 2021/10/27
- [PULL 46/56] tcg/optimize: Sink commutative operand swapping into fold functions, Richard Henderson, 2021/10/27
- [PULL 42/56] tcg/optimize: Split out fold_ix_to_i, Richard Henderson, 2021/10/27
- [PULL 48/56] tcg/optimize: Use fold_xx_to_i for orc, Richard Henderson, 2021/10/27
- [PULL 44/56] tcg/optimize: Expand fold_mulu2_i32 to all 4-arg multiplies, Richard Henderson, 2021/10/27
- [PULL 45/56] tcg/optimize: Expand fold_addsub2_i32 to 64-bit ops, Richard Henderson, 2021/10/27
- [PULL 47/56] tcg/optimize: Stop forcing z_mask to "garbage" for 32-bit values, Richard Henderson, 2021/10/27
- [PULL 50/56] tcg/optimize: Use fold_xi_to_x for div, Richard Henderson, 2021/10/27
- [PULL 55/56] tcg/optimize: Propagate sign info for bit counting, Richard Henderson, 2021/10/27