diff mbox series

[v3,22/48] tcg/optimize: Split out fold_movcond

Message ID 20211021210539.825582-23-richard.henderson@linaro.org (mailing list archive)
State New, archived
Headers show
Series tcg: optimize redundant sign extensions | expand

Commit Message

Richard Henderson Oct. 21, 2021, 9:05 p.m. UTC
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/optimize.c | 56 ++++++++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 25 deletions(-)

Comments

Philippe Mathieu-Daudé Oct. 22, 2021, 2:05 p.m. UTC | #1
On 10/21/21 23:05, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  tcg/optimize.c | 56 ++++++++++++++++++++++++++++----------------------
>  1 file changed, 31 insertions(+), 25 deletions(-)

> +static bool fold_movcond(OptContext *ctx, TCGOp *op)
> +{
> +    TCGOpcode opc = op->opc;
> +    TCGCond cond = op->args[5];
> +    int i = do_constant_folding_cond(opc, op->args[1], op->args[2], cond);
> +
> +    if (i >= 0) {
> +        return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]);
> +    }
> +
> +    if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) {
> +        uint64_t tv = arg_info(op->args[3])->val;
> +        uint64_t fv = arg_info(op->args[4])->val;
> +
> +        opc = (opc == INDEX_op_movcond_i32
> +               ? INDEX_op_setcond_i32 : INDEX_op_setcond_i64);
> +
> +        if (tv == 1 && fv == 0) {
> +            op->opc = opc;
> +            op->args[3] = cond;
> +        } else if (fv == 1 && tv == 0) {

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +            op->opc = opc;
> +            op->args[3] = tcg_invert_cond(cond);
> +        }
> +    }
> +    return false;
> +}
Luis Fernando Fujita Pires Oct. 22, 2021, 5:34 p.m. UTC | #2
From: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  tcg/optimize.c | 56 ++++++++++++++++++++++++++++----------------------
>  1 file changed, 31 insertions(+), 25 deletions(-)

Reviewed-by: Luis Pires <luis.pires@eldorado.org.br>

--
Luis Pires
Instituto de Pesquisas ELDORADO
Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>
diff mbox series

Patch

diff --git a/tcg/optimize.c b/tcg/optimize.c
index eb6f1581ac..ed5a304089 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -917,6 +917,34 @@  static bool fold_mb(OptContext *ctx, TCGOp *op)
     return true;
 }
 
+static bool fold_movcond(OptContext *ctx, TCGOp *op)
+{
+    TCGOpcode opc = op->opc;
+    TCGCond cond = op->args[5];
+    int i = do_constant_folding_cond(opc, op->args[1], op->args[2], cond);
+
+    if (i >= 0) {
+        return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]);
+    }
+
+    if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) {
+        uint64_t tv = arg_info(op->args[3])->val;
+        uint64_t fv = arg_info(op->args[4])->val;
+
+        opc = (opc == INDEX_op_movcond_i32
+               ? INDEX_op_setcond_i32 : INDEX_op_setcond_i64);
+
+        if (tv == 1 && fv == 0) {
+            op->opc = opc;
+            op->args[3] = cond;
+        } else if (fv == 1 && tv == 0) {
+            op->opc = opc;
+            op->args[3] = tcg_invert_cond(cond);
+        }
+    }
+    return false;
+}
+
 static bool fold_multiply(OptContext *ctx, TCGOp *op)
 {
     return fold_const2(ctx, op);
@@ -1700,31 +1728,6 @@  void tcg_optimize(TCGContext *s)
             }
             break;
 
-        CASE_OP_32_64(movcond):
-            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])) {
-                uint64_t tv = arg_info(op->args[3])->val;
-                uint64_t fv = arg_info(op->args[4])->val;
-                TCGCond cond = op->args[5];
-
-                if (fv == 1 && tv == 0) {
-                    cond = tcg_invert_cond(cond);
-                } else if (!(tv == 1 && fv == 0)) {
-                    break;
-                }
-                op->args[3] = cond;
-                op->opc = opc = (opc == INDEX_op_movcond_i32
-                                 ? INDEX_op_setcond_i32
-                                 : INDEX_op_setcond_i64);
-            }
-            break;
-
-
         default:
             break;
 
@@ -1776,6 +1779,9 @@  void tcg_optimize(TCGContext *s)
         case INDEX_op_mb:
             done = fold_mb(&ctx, op);
             break;
+        CASE_OP_32_64(movcond):
+            done = fold_movcond(&ctx, op);
+            break;
         CASE_OP_32_64(mul):
         CASE_OP_32_64(mulsh):
         CASE_OP_32_64(muluh):