summaryrefslogtreecommitdiff
path: root/tcg
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2024-09-06 21:00:10 -0700
committerRichard Henderson <richard.henderson@linaro.org>2024-09-22 06:54:49 +0200
commit141125e08cf422e22d40b0114a265c83d888767a (patch)
treea20ba416fd3e5366dea6442f5b305660c1c48834 /tcg
parentfcc54e7bf56ba627f9b6ac4a32c6b446d2591ccf (diff)
tcg/optimize: Fold movcond with true and false values identical
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>
Diffstat (limited to 'tcg')
-rw-r--r--tcg/optimize.c5
1 files changed, 5 insertions, 0 deletions
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.