[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/48] tcg/optimize: Change fail return for do_constant_folding_c
From: |
Richard Henderson |
Subject: |
[PATCH 10/48] tcg/optimize: Change fail return for do_constant_folding_cond* |
Date: |
Sun, 29 Aug 2021 23:24:13 -0700 |
Return -1 instead of 2 for failure.
This us to use comparisons against 0 for all cases.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/optimize.c | 145 +++++++++++++++++++++++++------------------------
1 file changed, 74 insertions(+), 71 deletions(-)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 96012a6da8..39a65d305f 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -502,10 +502,12 @@ static bool do_constant_folding_cond_eq(TCGCond c)
}
}
-/* Return 2 if the condition can't be simplified, and the result
- of the condition (0 or 1) if it can */
-static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
- TCGArg y, TCGCond c)
+/*
+ * Return -1 if the condition can't be simplified,
+ * and the result of the condition (0 or 1) if it can.
+ */
+static int do_constant_folding_cond(TCGOpcode op, TCGArg x,
+ TCGArg y, TCGCond c)
{
uint64_t xv = arg_info(x)->val;
uint64_t yv = arg_info(y)->val;
@@ -527,15 +529,17 @@ static TCGArg do_constant_folding_cond(TCGOpcode op,
TCGArg x,
case TCG_COND_GEU:
return 1;
default:
- return 2;
+ return -1;
}
}
- return 2;
+ return -1;
}
-/* Return 2 if the condition can't be simplified, and the result
- of the condition (0 or 1) if it can */
-static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c)
+/*
+ * Return -1 if the condition can't be simplified,
+ * and the result of the condition (0 or 1) if it can.
+ */
+static int do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c)
{
TCGArg al = p1[0], ah = p1[1];
TCGArg bl = p2[0], bh = p2[1];
@@ -565,7 +569,7 @@ static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg
*p2, TCGCond c)
if (args_are_copies(al, bl) && args_are_copies(ah, bh)) {
return do_constant_folding_cond_eq(c);
}
- return 2;
+ return -1;
}
static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2)
@@ -1321,22 +1325,21 @@ void tcg_optimize(TCGContext *s)
break;
CASE_OP_32_64(setcond):
- tmp = do_constant_folding_cond(opc, op->args[1],
- op->args[2], op->args[3]);
- if (tmp != 2) {
- tcg_opt_gen_movi(&ctx, op, op->args[0], tmp);
+ i = do_constant_folding_cond(opc, op->args[1],
+ op->args[2], op->args[3]);
+ if (i >= 0) {
+ tcg_opt_gen_movi(&ctx, op, op->args[0], i);
continue;
}
break;
CASE_OP_32_64(brcond):
- tmp = do_constant_folding_cond(opc, op->args[0],
- op->args[1], op->args[2]);
- switch (tmp) {
- case 0:
+ i = do_constant_folding_cond(opc, op->args[0],
+ op->args[1], op->args[2]);
+ if (i == 0) {
tcg_op_remove(s, op);
continue;
- case 1:
+ } else if (i > 0) {
memset(&ctx.temps_used, 0, sizeof(ctx.temps_used));
op->opc = opc = INDEX_op_br;
op->args[0] = op->args[3];
@@ -1345,10 +1348,10 @@ void tcg_optimize(TCGContext *s)
break;
CASE_OP_32_64(movcond):
- tmp = do_constant_folding_cond(opc, op->args[1],
- op->args[2], op->args[5]);
- if (tmp != 2) {
- tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4-tmp]);
+ i = do_constant_folding_cond(opc, op->args[1],
+ op->args[2], op->args[5]);
+ if (i >= 0) {
+ tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4 - i]);
continue;
}
if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) {
@@ -1412,14 +1415,14 @@ void tcg_optimize(TCGContext *s)
break;
case INDEX_op_brcond2_i32:
- tmp = do_constant_folding_cond2(&op->args[0], &op->args[2],
- op->args[4]);
- if (tmp == 0) {
+ i = do_constant_folding_cond2(&op->args[0], &op->args[2],
+ op->args[4]);
+ if (i == 0) {
do_brcond_false:
tcg_op_remove(s, op);
continue;
}
- if (tmp == 1) {
+ if (i > 0) {
do_brcond_true:
op->opc = opc = INDEX_op_br;
op->args[0] = op->args[5];
@@ -1443,20 +1446,20 @@ void tcg_optimize(TCGContext *s)
if (op->args[4] == TCG_COND_EQ) {
/* Simplify EQ comparisons where one of the pairs
can be simplified. */
- tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
- op->args[0], op->args[2],
- TCG_COND_EQ);
- if (tmp == 0) {
+ i = do_constant_folding_cond(INDEX_op_brcond_i32,
+ op->args[0], op->args[2],
+ TCG_COND_EQ);
+ if (i == 0) {
goto do_brcond_false;
- } else if (tmp == 1) {
+ } else if (i > 0) {
goto do_brcond_high;
}
- tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
- op->args[1], op->args[3],
- TCG_COND_EQ);
- if (tmp == 0) {
+ i = do_constant_folding_cond(INDEX_op_brcond_i32,
+ op->args[1], op->args[3],
+ TCG_COND_EQ);
+ if (i == 0) {
goto do_brcond_false;
- } else if (tmp != 1) {
+ } else if (i < 0) {
break;
}
do_brcond_low:
@@ -1470,31 +1473,31 @@ void tcg_optimize(TCGContext *s)
if (op->args[4] == TCG_COND_NE) {
/* Simplify NE comparisons where one of the pairs
can be simplified. */
- tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
- op->args[0], op->args[2],
- TCG_COND_NE);
- if (tmp == 0) {
+ i = do_constant_folding_cond(INDEX_op_brcond_i32,
+ op->args[0], op->args[2],
+ TCG_COND_NE);
+ if (i == 0) {
goto do_brcond_high;
- } else if (tmp == 1) {
+ } else if (i > 0) {
goto do_brcond_true;
}
- tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
- op->args[1], op->args[3],
- TCG_COND_NE);
- if (tmp == 0) {
+ i = do_constant_folding_cond(INDEX_op_brcond_i32,
+ op->args[1], op->args[3],
+ TCG_COND_NE);
+ if (i == 0) {
goto do_brcond_low;
- } else if (tmp == 1) {
+ } else if (i > 0) {
goto do_brcond_true;
}
}
break;
case INDEX_op_setcond2_i32:
- tmp = do_constant_folding_cond2(&op->args[1], &op->args[3],
- op->args[5]);
- if (tmp != 2) {
+ 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], tmp);
+ tcg_opt_gen_movi(&ctx, op, op->args[0], i);
continue;
}
if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE)
@@ -1516,20 +1519,20 @@ void tcg_optimize(TCGContext *s)
if (op->args[5] == TCG_COND_EQ) {
/* Simplify EQ comparisons where one of the pairs
can be simplified. */
- tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[1], op->args[3],
- TCG_COND_EQ);
- if (tmp == 0) {
+ 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 (tmp == 1) {
+ } else if (i > 0) {
goto do_setcond_high;
}
- tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[2], op->args[4],
- TCG_COND_EQ);
- if (tmp == 0) {
+ 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 (tmp != 1) {
+ } else if (i < 0) {
break;
}
do_setcond_low:
@@ -1543,20 +1546,20 @@ void tcg_optimize(TCGContext *s)
if (op->args[5] == TCG_COND_NE) {
/* Simplify NE comparisons where one of the pairs
can be simplified. */
- tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[1], op->args[3],
- TCG_COND_NE);
- if (tmp == 0) {
+ 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 (tmp == 1) {
+ } else if (i > 0) {
goto do_setcond_const;
}
- tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
- op->args[2], op->args[4],
- TCG_COND_NE);
- if (tmp == 0) {
+ 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 (tmp == 1) {
+ } else if (i > 0) {
goto do_setcond_const;
}
}
--
2.25.1
- Re: [PATCH 13/48] tcg/optimize: Use a boolean to avoid a mass of continues, (continued)
- [PATCH 16/48] tcg/optimize: Split out fold_setcond2, Richard Henderson, 2021/08/30
- [PATCH 19/48] tcg/optimize: Split out fold_setcond, Richard Henderson, 2021/08/30
- [PATCH 18/48] tcg/optimize: Split out fold_brcond, Richard Henderson, 2021/08/30
- [PATCH 17/48] tcg/optimize: Split out fold_brcond2, Richard Henderson, 2021/08/30
- [PATCH 20/48] tcg/optimize: Split out fold_mulu2_i32, Richard Henderson, 2021/08/30
- [PATCH 21/48] tcg/optimize: Split out fold_addsub2_i32, Richard Henderson, 2021/08/30
- [PATCH 22/48] tcg/optimize: Split out fold_movcond, Richard Henderson, 2021/08/30
- [PATCH 23/48] tcg/optimize: Split out fold_extract2, Richard Henderson, 2021/08/30
- [PATCH 15/48] tcg/optimize: Split out fold_const{1,2}, Richard Henderson, 2021/08/30
- [PATCH 10/48] tcg/optimize: Change fail return for do_constant_folding_cond*,
Richard Henderson <=
- [PATCH 25/48] tcg/optimize: Split out fold_deposit, Richard Henderson, 2021/08/30
- [PATCH 24/48] tcg/optimize: Split out fold_extract, fold_sextract, Richard Henderson, 2021/08/30
- [PATCH 27/48] tcg/optimize: Split out fold_bswap, Richard Henderson, 2021/08/30
- [PATCH 29/48] tcg/optimize: Split out fold_mov, Richard Henderson, 2021/08/30
- [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