qemu-e2k/target
Matheus Tavares Bernardino bee1fc56c2 Hexagon (translate.c): avoid redundant PC updates on COF
When there is a conditional change of flow or an endloop instruction, we
preload HEX_REG_PC with ctx->next_PC at gen_start_packet(). Nonetheless,
we still generate TCG code to do this update again at gen_goto_tb() when
the condition for the COF is not met, thus producing redundant
instructions. This can be seen with the following packet:

 0x004002e4:  0x5c20d000 {       if (!P0) jump:t PC+0 }

Which generates this TCG code:

   ---- 004002e4
-> mov_i32 pc,$0x4002e8
   and_i32 loc9,p0,$0x1
   mov_i32 branch_taken,loc9
   add_i32 pkt_cnt,pkt_cnt,$0x2
   add_i32 insn_cnt,insn_cnt,$0x2
   brcond_i32 branch_taken,$0x0,ne,$L1
   goto_tb $0x0
   mov_i32 pc,$0x4002e4
   exit_tb $0x7fb0c36e5200
   set_label $L1
   goto_tb $0x1
-> mov_i32 pc,$0x4002e8
   exit_tb $0x7fb0c36e5201
   set_label $L0
   exit_tb $0x7fb0c36e5203

Note that even after optimizations, the redundant PC update is still
present:

   ---- 004002e4
-> mov_i32 pc,$0x4002e8                     sync: 0  dead: 0 1  pref=0xffff
   mov_i32 branch_taken,$0x1                sync: 0  dead: 0 1  pref=0xffff
   add_i32 pkt_cnt,pkt_cnt,$0x2             sync: 0  dead: 0 1  pref=0xffff
   add_i32 insn_cnt,insn_cnt,$0x2           sync: 0  dead: 0 1 2  pref=0xffff
   goto_tb $0x1
-> mov_i32 pc,$0x4002e8                     sync: 0  dead: 0 1  pref=0xffff
   exit_tb $0x7fb0c36e5201
   set_label $L0
   exit_tb $0x7fb0c36e5203

With this patch, the second redundant update is properly discarded.

Note that we need the additional "move_to_pc" flag instead of just
avoiding the update whenever `dest == ctx->next_PC`, as that could
potentially skip updates from a COF with met condition, whose
ctx->branch_dest just happens to be equal to ctx->next_PC.

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Reviewed-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>
Message-Id: <fc059153c3f0526d97b7f13450c02b276b0908e1.1679519341.git.quic_mathbern@quicinc.com>
2023-04-21 09:32:51 -07:00
..
alpha target/alpha: Remove `NB_MMU_MODES` define 2023-03-13 06:44:37 -07:00
arm target/arm: Don't advertise aarch64-pauth.xml to gdb 2023-03-21 13:19:08 +00:00
avr target/avr: Avoid use of tcg_const_i32 throughout 2023-03-13 06:44:37 -07:00
cris target/cris: Avoid use of tcg_const_i32 throughout 2023-03-13 06:44:37 -07:00
hexagon Hexagon (translate.c): avoid redundant PC updates on COF 2023-04-21 09:32:51 -07:00
hppa target/hppa: Avoid use of tcg_const_i32 throughout 2023-03-13 06:44:37 -07:00
i386 *: Add missing includes of qemu/error-report.h 2023-03-22 15:06:57 +00:00
loongarch target/loongarch: Remove `NB_MMU_MODES` define 2023-03-13 06:44:37 -07:00
m68k target/m68k: Use tcg_constant_i32 in gen_ea_mode 2023-03-13 07:03:39 -07:00
microblaze target/microblaze: Remove `NB_MMU_MODES` define 2023-03-13 06:44:37 -07:00
mips *: Add missing includes of qemu/error-report.h 2023-03-22 15:06:57 +00:00
nios2 target/nios2: Remove `NB_MMU_MODES` define 2023-03-13 06:44:37 -07:00
openrisc target/openrisc: Remove `NB_MMU_MODES` define 2023-03-13 06:44:37 -07:00
ppc target/ppc: Avoid tcg_const_* in translate.c 2023-03-13 07:03:39 -07:00
riscv target/riscv: Remove `NB_MMU_MODES` define 2023-03-13 06:44:37 -07:00
rx target/rx: Avoid tcg_const_i32 2023-03-13 06:44:37 -07:00
s390x *: Add missing includes of qemu/error-report.h 2023-03-22 15:06:57 +00:00
sh4 target/sh4: Honor QEMU_LOG_FILENAME with QEMU_LOG=cpu 2023-03-16 10:31:25 +01:00
sparc tcg/sparc: Avoid tcg_const_tl in gen_edge 2023-03-13 06:44:37 -07:00
tricore target/tricore: Use min/max for saturate 2023-03-13 07:03:39 -07:00
xtensa target/xtensa: Remove `NB_MMU_MODES` define 2023-03-13 06:44:37 -07:00
Kconfig
meson.build