[PATCH 00/16] tcg: Introduce INDEX_op_lea

Richard Henderson posted 16 patches 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260828224451.1564072-1-richard.henderson@linaro.org
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>, Song Gao <17746591750@163.com>, Bibo Mao <maobibo@loongson.cn>, Xianglai Li <lixianglai@loongson.cn>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu@processmission.com>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>, Cornelia Huck <cohuck@redhat.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, WANG Xuerui <git@xen0n.name>, Stefan Weil <sw@weilnetz.de>
There is a newer version of this series
include/tcg/tcg-op-common.h                   |  4 +
include/tcg/tcg-op.h                          |  2 +
include/tcg/tcg-opc.h                         |  1 +
tcg/aarch64/tcg-target-has.h                  |  4 +
tcg/loongarch64/tcg-target-has.h              |  3 +
tcg/ppc64/tcg-target-has.h                    |  3 +
tcg/riscv64/tcg-target-has.h                  | 11 +++
tcg/s390x/tcg-target-has.h                    |  4 +
tcg/sparc64/tcg-target-has.h                  |  3 +
tcg/tci/tcg-target-has.h                      |  3 +
tcg/x86_64/tcg-target-con-set.h               |  1 +
tcg/x86_64/tcg-target-has.h                   |  3 +
tcg/x86_64/tcg-target.h                       |  3 +
target/alpha/translate.c                      | 20 ++---
target/i386/tcg/translate.c                   | 27 +++---
target/s390x/tcg/translate.c                  |  4 +-
tcg/optimize.c                                | 65 ++++++++++++++
tcg/tcg-op.c                                  | 90 +++++++++++++++++++
tcg/tcg.c                                     | 61 ++++++++-----
docs/devel/tcg-ops.rst                        |  4 +
.../tcg/insn_trans/trans_arith.c.inc          |  4 +-
target/riscv/tcg/insn_trans/trans_rvb.c.inc   |  5 +-
tcg/aarch64/tcg-target.c.inc                  | 11 +++
tcg/loongarch64/tcg-insn-defs.c.inc           | 30 ++++++-
tcg/loongarch64/tcg-target.c.inc              | 15 ++++
tcg/ppc64/tcg-target.c.inc                    |  3 +
tcg/riscv64/tcg-target.c.inc                  | 17 ++++
tcg/s390x/tcg-target.c.inc                    | 14 +++
tcg/sparc64/tcg-target.c.inc                  |  3 +
tcg/tci/tcg-target.c.inc                      |  4 +
tcg/x86_64/tcg-target.c.inc                   | 79 +++++++++-------
31 files changed, 413 insertions(+), 88 deletions(-)
[PATCH 00/16] tcg: Introduce INDEX_op_lea
Posted by Richard Henderson 4 weeks ago
Add a complex addressing mode primitive, and some trivial use cases.

This came up in conversation with Matt Turner re his inline jump cache
expansion.  In particular,

-    tcg_gen_shli_i64(h, h, 4);
-    tcg_gen_add_i64(ent, jc, ent);
+    tcg_gen_lea_i64(ent, jc, h, 4, 0);

With the use case in target/i386/tcg, we get nearly full coverage of
all the possible use cases.  The only thing I didn't immediately see
is shifts > 3, which could be visible with loongarch64 guests.

There are plenty of other places in target/ that could use this, but
the shift/add/imm extraction/generation are inconveniently separated.
E.g. m68k address generation, arm add-shifted, etc.

It may not even be worth converting those, but instead adding some
trivial peepholing along the lines of Matt's user-only guest displacement.


r~


Richard Henderson (16):
  tcg: Sort all_outop[] by INDEX name
  tcg: Add INDEX_op_lea
  tcg: Add tcg_gen_lea_{i32,i64,tl}
  tcg/optimize: Handle INDEX_op_lea
  target/alpha: Use tcg_gen_lea_i64 for S{4,8}ADD{L,Q}
  target/loongarch: Use tcg_gen_lea_tl for ALSL
  target/riscv: Use tcg_gen_lea_tl for SH*ADD
  target/s390x: Use tcg_gen_lea_i64 in get_address
  target/i386: Use tcg_gen_lea_tl in gen_lea_modrm_1
  tcg/x86_64: Introduce TCG_REG_NONE
  tcg/x86_64: Implement INDEX_op_lea
  tcg/loongarch64: Import SLADD insns
  tcg/loongarch64: Implement INDEX_op_lea
  tcg/aarch64: Implement INDEX_op_lea
  tcg/riscv64: Implement INDEX_op_lea
  tcg/s390x: Implement INDEX_op_lea

 include/tcg/tcg-op-common.h                   |  4 +
 include/tcg/tcg-op.h                          |  2 +
 include/tcg/tcg-opc.h                         |  1 +
 tcg/aarch64/tcg-target-has.h                  |  4 +
 tcg/loongarch64/tcg-target-has.h              |  3 +
 tcg/ppc64/tcg-target-has.h                    |  3 +
 tcg/riscv64/tcg-target-has.h                  | 11 +++
 tcg/s390x/tcg-target-has.h                    |  4 +
 tcg/sparc64/tcg-target-has.h                  |  3 +
 tcg/tci/tcg-target-has.h                      |  3 +
 tcg/x86_64/tcg-target-con-set.h               |  1 +
 tcg/x86_64/tcg-target-has.h                   |  3 +
 tcg/x86_64/tcg-target.h                       |  3 +
 target/alpha/translate.c                      | 20 ++---
 target/i386/tcg/translate.c                   | 27 +++---
 target/s390x/tcg/translate.c                  |  4 +-
 tcg/optimize.c                                | 65 ++++++++++++++
 tcg/tcg-op.c                                  | 90 +++++++++++++++++++
 tcg/tcg.c                                     | 61 ++++++++-----
 docs/devel/tcg-ops.rst                        |  4 +
 .../tcg/insn_trans/trans_arith.c.inc          |  4 +-
 target/riscv/tcg/insn_trans/trans_rvb.c.inc   |  5 +-
 tcg/aarch64/tcg-target.c.inc                  | 11 +++
 tcg/loongarch64/tcg-insn-defs.c.inc           | 30 ++++++-
 tcg/loongarch64/tcg-target.c.inc              | 15 ++++
 tcg/ppc64/tcg-target.c.inc                    |  3 +
 tcg/riscv64/tcg-target.c.inc                  | 17 ++++
 tcg/s390x/tcg-target.c.inc                    | 14 +++
 tcg/sparc64/tcg-target.c.inc                  |  3 +
 tcg/tci/tcg-target.c.inc                      |  4 +
 tcg/x86_64/tcg-target.c.inc                   | 79 +++++++++-------
 31 files changed, 413 insertions(+), 88 deletions(-)

-- 
2.53.0
Re: [PATCH 00/16] tcg: Introduce INDEX_op_lea
Posted by Matt Turner 4 weeks ago
On Fri, Aug 28, 2026 at 6:44 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Add a complex addressing mode primitive, and some trivial use cases.
>
> This came up in conversation with Matt Turner re his inline jump cache
> expansion.  In particular,
>
> -    tcg_gen_shli_i64(h, h, 4);
> -    tcg_gen_add_i64(ent, jc, ent);
> +    tcg_gen_lea_i64(ent, jc, h, 4, 0);
>
> With the use case in target/i386/tcg, we get nearly full coverage of
> all the possible use cases.  The only thing I didn't immediately see
> is shifts > 3, which could be visible with loongarch64 guests.
>
> There are plenty of other places in target/ that could use this, but
> the shift/add/imm extraction/generation are inconveniently separated.
> E.g. m68k address generation, arm add-shifted, etc.
>
> It may not even be worth converting those, but instead adding some
> trivial peepholing along the lines of Matt's user-only guest displacement.

This looks great to me, for what that's worth.

Reviewed-by: Matt Turner <mattst88@gmail.com>