[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 31/48] tcg/optimize: Split out fold_xx_to_x
From: |
Richard Henderson |
Subject: |
[PATCH 31/48] tcg/optimize: Split out fold_xx_to_x |
Date: |
Sun, 29 Aug 2021 23:24:34 -0700 |
Pull the "op r, a, a => mov r, a" optimization into a function,
and use it in the outer opcode fold functions.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/optimize.c | 39 ++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index f48d0bc52d..cb05da7b39 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -704,8 +704,22 @@ static bool fold_xx_to_i(OptContext *ctx, TCGOp *op,
uint64_t i)
return false;
}
+/* If the binary operation has both arguments equal, fold to identity. */
+static bool fold_xx_to_x(OptContext *ctx, TCGOp *op)
+{
+ if (args_are_copies(op->args[1], op->args[2])) {
+ return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]);
+ }
+ return false;
+}
+
/*
* These outermost fold_<op> functions are sorted alphabetically.
+ *
+ * The ordering of the transformations should be:
+ * 1) those that produce a constant
+ * 2) those that produce a copy
+ * 3) those that produce information about the result value.
*/
static bool fold_add(OptContext *ctx, TCGOp *op)
@@ -748,7 +762,11 @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op)
static bool fold_and(OptContext *ctx, TCGOp *op)
{
- return fold_const2(ctx, op);
+ if (fold_const2(ctx, op) ||
+ fold_xx_to_x(ctx, op)) {
+ return true;
+ }
+ return false;
}
static bool fold_andc(OptContext *ctx, TCGOp *op)
@@ -1103,7 +1121,11 @@ static bool fold_not(OptContext *ctx, TCGOp *op)
static bool fold_or(OptContext *ctx, TCGOp *op)
{
- return fold_const2(ctx, op);
+ if (fold_const2(ctx, op) ||
+ fold_xx_to_x(ctx, op)) {
+ return true;
+ }
+ return false;
}
static bool fold_orc(OptContext *ctx, TCGOp *op)
@@ -1734,19 +1756,6 @@ void tcg_optimize(TCGContext *s)
break;
}
- /* Simplify expression for "op r, a, a => mov r, a" cases */
- switch (opc) {
- CASE_OP_32_64_VEC(or):
- CASE_OP_32_64_VEC(and):
- if (args_are_copies(op->args[1], op->args[2])) {
- tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]);
- continue;
- }
- break;
- default:
- break;
- }
-
/*
* Process each opcode.
* Sorted alphabetically by opcode as much as possible.
--
2.25.1
- [PATCH 30/48] tcg/optimize: Split out fold_xx_to_i, (continued)
- [PATCH 30/48] tcg/optimize: Split out fold_xx_to_i, Richard Henderson, 2021/08/30
- [PATCH 38/48] tcg/optimize: Split out fold_masks, Richard Henderson, 2021/08/30
- [PATCH 26/48] tcg/optimize: Split out fold_count_zeros, Richard Henderson, 2021/08/30
- [PATCH 28/48] tcg/optimize: Split out fold_dup, fold_dup2, Richard Henderson, 2021/08/30
- [PATCH 11/48] tcg/optimize: Return true from tcg_opt_gen_{mov,movi}, Richard Henderson, 2021/08/30
- [PATCH 32/48] tcg/optimize: Split out fold_xi_to_i, Richard Henderson, 2021/08/30
- [PATCH 34/48] tcg/optimize: Split out fold_to_not, Richard Henderson, 2021/08/30
- [PATCH 31/48] tcg/optimize: Split out fold_xx_to_x,
Richard Henderson <=
- [PATCH 33/48] tcg/optimize: Add type to OptContext, Richard Henderson, 2021/08/30
- [PATCH 35/48] tcg/optimize: Split out fold_sub_to_neg, Richard Henderson, 2021/08/30
- [PATCH 36/48] tcg/optimize: Split out fold_xi_to_x, Richard Henderson, 2021/08/30
- [PATCH 37/48] tcg/optimize: Split out fold_ix_to_i, Richard Henderson, 2021/08/30
- [PATCH 39/48] tcg/optimize: Expand fold_mulu2_i32 to all 4-arg multiplies, Richard Henderson, 2021/08/30
- [PATCH 40/48] tcg/optimize: Expand fold_addsub2_i32 to 64-bit ops, Richard Henderson, 2021/08/30
- [PATCH 41/48] tcg/optimize: Sink commutative operand swapping into fold functions, Richard Henderson, 2021/08/30
- [PATCH 47/48] tcg/optimize: Propagate sign info for bit counting, Richard Henderson, 2021/08/30