tcg/optimize: Fold movcond with true and false values identical
authorRichard Henderson <richard.henderson@linaro.org>
Sat, 7 Sep 2024 04:00:10 +0000 (21:00 -0700)
committerRichard Henderson <richard.henderson@linaro.org>
Sun, 22 Sep 2024 04:54:49 +0000 (06:54 +0200)
Fold "x = cond ? y : y" to "x = y".

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
tcg/optimize.c

index ba16ec27e243b682b22d747adf005255ce3c69c9..cf311790e058840f2a5ca148a3f1c2af42d12bc0 100644 (file)
@@ -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.