]> git.proxmox.com Git - qemu.git/commitdiff
tcg/optimize: prefer the "op a, a, b" form for commutative ops
authorAurelien Jarno <aurelien@aurel32.net>
Wed, 19 Sep 2012 20:00:22 +0000 (22:00 +0200)
committerAurelien Jarno <aurelien@aurel32.net>
Sat, 22 Sep 2012 13:10:21 +0000 (15:10 +0200)
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.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
tcg/optimize.c

index abe016a28afc2f57260c2e33ce4f9c31cb664904..c8ae50bc91943b78abd1bd4626f8c71361ea858f 100644 (file)
@@ -434,7 +434,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;