5544c1b
From a0b71ad6a3f8aeb8b5ea6d112a7afeadc7c004a4 Mon Sep 17 00:00:00 2001
5544c1b
From: Aurelien Jarno <aurelien@aurel32.net>
5544c1b
Date: Wed, 19 Sep 2012 22:00:22 +0200
5544c1b
Subject: [PATCH] tcg/optimize: prefer the "op a, a, b" form for commutative
5544c1b
 ops
5544c1b
5544c1b
The "op a, a, b" form is better handled on non-RISC host than the "op
5544c1b
a, b, a" form, so swap the arguments to this form when possible, and
5544c1b
when b is not a constant.
5544c1b
5544c1b
This reduces the number of generated instructions by a tiny bit.
5544c1b
5544c1b
Reviewed-by: Richard Henderson <rth@twiddle.net>
5544c1b
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1b
---
5544c1b
 tcg/optimize.c | 5 ++++-
5544c1b
 1 file changed, 4 insertions(+), 1 deletion(-)
5544c1b
5544c1b
diff --git a/tcg/optimize.c b/tcg/optimize.c
5544c1b
index abe016a..c8ae50b 100644
5544c1b
--- a/tcg/optimize.c
5544c1b
+++ b/tcg/optimize.c
5544c1b
@@ -434,7 +434,10 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1b
         CASE_OP_32_64(eqv):
5544c1b
         CASE_OP_32_64(nand):
5544c1b
         CASE_OP_32_64(nor):
5544c1b
-            if (temps[args[1]].state == TCG_TEMP_CONST) {
5544c1b
+            /* Prefer the constant in second argument, and then the form
5544c1b
+               op a, a, b, which is better handled on non-RISC hosts. */
5544c1b
+            if (temps[args[1]].state == TCG_TEMP_CONST || (args[0] == args[2]
5544c1b
+                && temps[args[2]].state != TCG_TEMP_CONST)) {
5544c1b
                 tmp = args[1];
5544c1b
                 args[1] = args[2];
5544c1b
                 args[2] = tmp;