Reviewed-by: Matt Turner <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
---
target/i386/tcg/translate.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 192cf43215e..ce14d1be028 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -1615,31 +1615,32 @@ static TCGv gen_shiftd_rm_T1(DisasContext *s, MemOp ot,
/* Compute the address, with a minimum number of TCG ops. */
static TCGv gen_lea_modrm_1(DisasContext *s, AddressParts a, bool is_vsib)
{
- TCGv ea = NULL;
+ TCGv ea = (a.base >= 0 ? cpu_regs[a.base] : NULL);
if (a.index >= 0 && !is_vsib) {
+ TCGv index = cpu_regs[a.index];
+
+ if (ea) {
+ tcg_gen_lea_tl(s->A0, ea, index, a.scale, a.disp);
+ return s->A0;
+ }
if (a.scale == 0) {
- ea = cpu_regs[a.index];
+ ea = index;
} else {
- tcg_gen_shli_tl(s->A0, cpu_regs[a.index], a.scale);
+ tcg_gen_shli_tl(s->A0, index, a.scale);
ea = s->A0;
}
- if (a.base >= 0) {
- tcg_gen_add_tl(s->A0, ea, cpu_regs[a.base]);
- ea = s->A0;
- }
- } else if (a.base >= 0) {
- ea = cpu_regs[a.base];
- }
- if (!ea) {
+ } else if (!ea) {
if (tb_cflags(s->base.tb) & CF_PCREL && a.base == -2) {
/* With cpu_eip ~= pc_save, the expression is pc-relative. */
tcg_gen_addi_tl(s->A0, cpu_eip, a.disp - s->pc_save);
} else {
tcg_gen_movi_tl(s->A0, a.disp);
}
- ea = s->A0;
- } else if (a.disp != 0) {
+ return s->A0;
+ }
+
+ if (a.disp != 0) {
tcg_gen_addi_tl(s->A0, ea, a.disp);
ea = s->A0;
}
--
2.53.0