[PATCH 06/12] tcg/optimize: Fold movcond with true and false values identical

Richard Henderson posted 12 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH 06/12] tcg/optimize: Fold movcond with true and false values identical
Posted by Richard Henderson 2 months, 2 weeks ago
Fold "x = cond ? y : y" to "x = y".

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/optimize.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index ba16ec27e2..cf311790e0 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1851,6 +1851,11 @@ static bool fold_movcond(OptContext *ctx, TCGOp *op)
 {
     int i;
 
+    /* If true and false values are the same, eliminate the cmp. */
+    if (args_are_copies(op->args[3], op->args[4])) {
+        return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[3]);
+    }
+
     /*
      * Canonicalize the "false" input reg to match the destination reg so
      * that the tcg backend can implement a "move if true" operation.
-- 
2.43.0
Re: [PATCH 06/12] tcg/optimize: Fold movcond with true and false values identical
Posted by Philippe Mathieu-Daudé 2 months, 2 weeks ago
On 8/9/24 04:26, Richard Henderson wrote:
> Fold "x = cond ? y : y" to "x = y".
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tcg/optimize.c | 5 +++++
>   1 file changed, 5 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>