On 17/2/25 00:07, Richard Henderson wrote:
Use the fully general extract opcodes instead.

Signed-off-by: Richard Henderson <richard.hender...@linaro.org>
---
  include/tcg/tcg-opc.h            |  10 -
  tcg/aarch64/tcg-target-has.h     |  10 -
  tcg/arm/tcg-target-has.h         |   4 -
  tcg/i386/tcg-target-has.h        |  10 -
  tcg/loongarch64/tcg-target-has.h |  10 -
  tcg/mips/tcg-target-has.h        |  13 -
  tcg/ppc/tcg-target-has.h         |  12 -
  tcg/riscv/tcg-target-has.h       |  10 -
  tcg/s390x/tcg-target-has.h       |  10 -
  tcg/sparc64/tcg-target-has.h     |  10 -
  tcg/tcg-has.h                    |   6 -
  tcg/tci/tcg-target-has.h         |  10 -
  tcg/optimize.c                   |  61 +----
  tcg/tcg-op.c                     | 430 ++++++++-----------------------
  tcg/tcg.c                        |  46 ----
  tcg/tci.c                        |  36 ---
  docs/devel/tcg-ops.rst           |  14 -
  tcg/aarch64/tcg-target.c.inc     |  22 +-
  tcg/arm/tcg-target.c.inc         |   7 -
  tcg/i386/tcg-target.c.inc        |  24 +-
  tcg/loongarch64/tcg-target.c.inc |  22 +-
  tcg/mips/tcg-target.c.inc        |  20 +-
  tcg/ppc/tcg-target.c.inc         |  17 +-
  tcg/riscv/tcg-target.c.inc       |  22 +-
  tcg/s390x/tcg-target.c.inc       |  22 +-
  tcg/sparc64/tcg-target.c.inc     |  14 +-
  tcg/tci/tcg-target.c.inc         | 102 +++-----
  27 files changed, 147 insertions(+), 827 deletions(-)


diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index fec6d678a2..48793ed439 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -414,17 +414,19 @@ void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, 
int32_t arg2)
      case -1:
          tcg_gen_mov_i32(ret, arg1);
          return;
-    case 0xff:
-        /* Don't recurse with tcg_gen_ext8u_i32.  */
-        if (TCG_TARGET_HAS_ext8u_i32) {
-            tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg1);
-            return;
-        }
-        break;
-    case 0xffff:
-        if (TCG_TARGET_HAS_ext16u_i32) {
-            tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg1);
-            return;
+    default:
+        /*
+         * Canonicalize on extract, if valid.  This aids x86 with its
+         * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
+         * which does not require matching operands.  Other backends can
+         * trivially expand the extract to AND during code generation.
+         */

           unsigned ofs = ctz32(arg2);
           int32_t val = arg2 >> ofs;

           if (!(val & (val + 1))) {
               unsigned len = cto32(val);
               if (TCG_TARGET_extract_valid(TCG_TYPE_I32, ofs, len)) {
                   tcg_gen_extract_i32(ret, arg1, ofs, len);
                   return;
               }
           }

+        if (!(arg2 & (arg2 + 1))) {
+            unsigned len = ctz32(~arg2);
+            if (TCG_TARGET_extract_valid(TCG_TYPE_I32, 0, len)) {
+                tcg_gen_extract_i32(ret, arg1, 0, len);
+                return;
+            }
          }
          break;
      }

Reply via email to