Blame 0053-tcg-Optimize-two-address-commutative-operations.patch

5544c1
From af2bf6bcc6614622c87d28e9d763b57408c17500 Mon Sep 17 00:00:00 2001
5544c1
From: Richard Henderson <rth@twiddle.net>
5544c1
Date: Fri, 21 Sep 2012 10:13:38 -0700
5544c1
Subject: [PATCH] tcg: Optimize two-address commutative operations
5544c1
5544c1
While swapping constants to the second operand, swap
5544c1
sources matching destinations to the first operand.
5544c1
5544c1
Signed-off-by: Richard Henderson <rth@twiddle.net>
5544c1
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 tcg/optimize.c | 15 ++++++++++++++-
5544c1
 1 file changed, 14 insertions(+), 1 deletion(-)
5544c1
5544c1
diff --git a/tcg/optimize.c b/tcg/optimize.c
5544c1
index 26038a6..1be7631 100644
5544c1
--- a/tcg/optimize.c
5544c1
+++ b/tcg/optimize.c
5544c1
@@ -334,6 +334,8 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1
     const TCGOpDef *def;
5544c1
     TCGArg *gen_args;
5544c1
     TCGArg tmp;
5544c1
+    TCGCond cond;
5544c1
+
5544c1
     /* Array VALS has an element for each temp.
5544c1
        If this temp holds a constant then its value is kept in VALS' element.
5544c1
        If this temp is a copy of other ones then this equivalence class'
5544c1
@@ -395,13 +397,24 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1
             }
5544c1
             break;
5544c1
         CASE_OP_32_64(movcond):
5544c1
+            cond = args[5];
5544c1
             if (temps[args[1]].state == TCG_TEMP_CONST
5544c1
                 && temps[args[2]].state != TCG_TEMP_CONST) {
5544c1
                 tmp = args[1];
5544c1
                 args[1] = args[2];
5544c1
                 args[2] = tmp;
5544c1
-                args[5] = tcg_swap_cond(args[5]);
5544c1
+                cond = tcg_swap_cond(cond);
5544c1
+            }
5544c1
+            /* For movcond, we canonicalize the "false" input reg to match
5544c1
+               the destination reg so that the tcg backend can implement
5544c1
+               a "move if true" operation.  */
5544c1
+            if (args[0] == args[3]) {
5544c1
+                tmp = args[3];
5544c1
+                args[3] = args[4];
5544c1
+                args[4] = tmp;
5544c1
+                cond = tcg_invert_cond(cond);
5544c1
             }
5544c1
+            args[5] = cond;
5544c1
         default:
5544c1
             break;
5544c1
         }
5544c1
-- 
5544c1
1.7.12.1
5544c1