Patchwork [8/9] tcg/optimize: prefer the "op a, a, b" form for commutative ops

login
register
mail settings
Submitter Aurelien Jarno
Date Sept. 19, 2012, 8 p.m.
Message ID <1348084823-18277-9-git-send-email-aurelien@aurel32.net>
Download mbox | patch
Permalink /patch/185214/
State New
Headers show

Comments

Aurelien Jarno - Sept. 19, 2012, 8 p.m.
The "op a, a, b" form is better handled on non-RISC host than the "op
a, b, a" form, so swap the arguments to this form when possible, and
when b is not a constant.

This reduces the number of generated instructions by a tiny bit.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 tcg/optimize.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Richard Henderson - Sept. 19, 2012, 9:49 p.m.
On 09/19/2012 01:00 PM, Aurelien Jarno wrote:
> The "op a, a, b" form is better handled on non-RISC host than the "op
> a, b, a" form, so swap the arguments to this form when possible, and
> when b is not a constant.
> 
> This reduces the number of generated instructions by a tiny bit.
> 
> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~

Patch

diff --git a/tcg/optimize.c b/tcg/optimize.c
index 6e2a37d..3495b7a 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -432,7 +432,10 @@  static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
         CASE_OP_32_64(eqv):
         CASE_OP_32_64(nand):
         CASE_OP_32_64(nor):
-            if (temps[args[1]].state == TCG_TEMP_CONST) {
+            /* Prefer the constant in second argument, and then the form
+               op a, a, b, which is better handled on non-RISC hosts. */
+            if (temps[args[1]].state == TCG_TEMP_CONST || (args[0] == args[2]
+                && temps[args[2]].state != TCG_TEMP_CONST)) {
                 tmp = args[1];
                 args[1] = args[2];
                 args[2] = tmp;