aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-08-24 09:09:35 -0700
committerRichard Henderson <richard.henderson@linaro.org>2021-10-27 17:11:22 -0700
commitbc47b1aa5be9f90cdbf7fbb01717e4259f717bb9 (patch)
treed6adf05c94b860bdaa0097dc81f142e214e47077
parent2f9f08ba43df3ea76124f66ae3fe99a96a0a072f (diff)
tcg/optimize: Split out fold_setcond2
Reduce some code duplication by folding the NE and EQ cases. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
-rw-r--r--tcg/optimize.c145
1 files changed, 72 insertions, 73 deletions
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 5c3f8e8fcd..80e43deb8e 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -854,6 +854,75 @@ static bool fold_remainder(OptContext *ctx, TCGOp *op)
return fold_const2(ctx, op);
}
+static bool fold_setcond2(OptContext *ctx, TCGOp *op)
+{
+ TCGCond cond = op->args[5];
+ int i = do_constant_folding_cond2(&op->args[1], &op->args[3], cond);
+ int inv = 0;
+
+ if (i >= 0) {
+ goto do_setcond_const;
+ }
+
+ switch (cond) {
+ case TCG_COND_LT:
+ case TCG_COND_GE:
+ /*
+ * Simplify LT/GE comparisons vs zero to a single compare
+ * vs the high word of the input.
+ */
+ if (arg_is_const(op->args[3]) && arg_info(op->args[3])->val == 0 &&
+ arg_is_const(op->args[4]) && arg_info(op->args[4])->val == 0) {
+ goto do_setcond_high;
+ }
+ break;
+
+ case TCG_COND_NE:
+ inv = 1;
+ QEMU_FALLTHROUGH;
+ case TCG_COND_EQ:
+ /*
+ * Simplify EQ/NE comparisons where one of the pairs
+ * can be simplified.
+ */
+ i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[1],
+ op->args[3], cond);
+ switch (i ^ inv) {
+ case 0:
+ goto do_setcond_const;
+ case 1:
+ goto do_setcond_high;
+ }
+
+ i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[2],
+ op->args[4], cond);
+ switch (i ^ inv) {
+ case 0:
+ goto do_setcond_const;
+ case 1:
+ op->args[2] = op->args[3];
+ op->args[3] = cond;
+ op->opc = INDEX_op_setcond_i32;
+ break;
+ }
+ break;
+
+ default:
+ break;
+
+ do_setcond_high:
+ op->args[1] = op->args[2];
+ op->args[2] = op->args[4];
+ op->args[3] = cond;
+ op->opc = INDEX_op_setcond_i32;
+ break;
+ }
+ return false;
+
+ do_setcond_const:
+ return tcg_opt_gen_movi(ctx, op, op->args[0], i);
+}
+
static bool fold_shift(OptContext *ctx, TCGOp *op)
{
return fold_const2(ctx, op);
@@ -1653,79 +1722,6 @@ void tcg_optimize(TCGContext *s)
}
break;
- case INDEX_op_setcond2_i32:
- i = do_constant_folding_cond2(&op->args[1], &op->args[3],
- op->args[5]);
- if (i >= 0) {
- do_setcond_const:
- tcg_opt_gen_movi(&ctx, op, op->args[0], i);
- continue;
- }
- if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE)
- && arg_is_const(op->args[3])
- && arg_info(op->args[3])->val == 0
- && arg_is_const(op->args[4])
- && arg_info(op->args[4])->val == 0) {
- /* Simplify LT/GE comparisons vs zero to a single compare
- vs the high word of the input. */
- do_setcond_high:
- reset_temp(op->args[0]);
- arg_info(op->args[0])->z_mask = 1;
- op->opc = INDEX_op_setcond_i32;
- op->args[1] = op->args[2];
- op->args[2] = op->args[4];
- op->args[3] = op->args[5];
- break;
- }
- if (op->args[5] == TCG_COND_EQ) {
- /* Simplify EQ comparisons where one of the pairs
- can be simplified. */
- i = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[1], op->args[3],
- TCG_COND_EQ);
- if (i == 0) {
- goto do_setcond_const;
- } else if (i > 0) {
- goto do_setcond_high;
- }
- i = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[2], op->args[4],
- TCG_COND_EQ);
- if (i == 0) {
- goto do_setcond_high;
- } else if (i < 0) {
- break;
- }
- do_setcond_low:
- reset_temp(op->args[0]);
- arg_info(op->args[0])->z_mask = 1;
- op->opc = INDEX_op_setcond_i32;
- op->args[2] = op->args[3];
- op->args[3] = op->args[5];
- break;
- }
- if (op->args[5] == TCG_COND_NE) {
- /* Simplify NE comparisons where one of the pairs
- can be simplified. */
- i = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[1], op->args[3],
- TCG_COND_NE);
- if (i == 0) {
- goto do_setcond_high;
- } else if (i > 0) {
- goto do_setcond_const;
- }
- i = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[2], op->args[4],
- TCG_COND_NE);
- if (i == 0) {
- goto do_setcond_low;
- } else if (i > 0) {
- goto do_setcond_const;
- }
- }
- break;
-
default:
break;
@@ -1813,6 +1809,9 @@ void tcg_optimize(TCGContext *s)
CASE_OP_32_64(shr):
done = fold_shift(&ctx, op);
break;
+ case INDEX_op_setcond2_i32:
+ done = fold_setcond2(&ctx, op);
+ break;
CASE_OP_32_64_VEC(sub):
done = fold_sub(&ctx, op);
break;