Skip to content

Commit 6560513

Browse files
artemiy-volkovMichielDerhaeg
authored andcommitted
arcv: fuse load-immediate with dependent branch
With this commit, we allow a load-immediate to be macro-op fused with a successive conditional branch that is dependent on it, e.g.: li t0, #imm bge t1, t0, .label Additionally, add a new testcase to check that this fusion type is handled correctly. Signed-off-by: Artemiy Volkov <artemiy@synopsys.com>
1 parent 660bc69 commit 6560513

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

gcc/config/riscv/riscv-protos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ extern unsigned int th_int_get_save_adjustment (void);
822822
extern rtx th_int_adjust_cfi_prologue (unsigned int);
823823
extern const char *th_asm_output_opcode (FILE *asm_out_file, const char *p);
824824

825+
extern bool riscv_macro_fusion_p ();
825826
extern bool riscv_is_micro_arch (enum riscv_microarchitecture_type);
826827

827828
#ifdef RTX_CODE

gcc/config/riscv/riscv.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10324,7 +10324,7 @@ riscv_sched_variable_issue (FILE *, int, rtx_insn *insn, int more)
1032410324
/* Implement TARGET_SCHED_MACRO_FUSION_P. Return true if target supports
1032510325
instruction fusion of some sort. */
1032610326

10327-
static bool
10327+
bool
1032810328
riscv_macro_fusion_p (void)
1032910329
{
1033010330
return tune_param->fusible_ops != RISCV_FUSE_NOTHING;
@@ -10470,7 +10470,18 @@ arcv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr)
1047010470
/* prev and curr are simple SET insns i.e. no flag setting or branching. */
1047110471
bool simple_sets_p = prev_set && curr_set && !any_condjump_p (curr);
1047210472

10473-
/* Don't handle anything with a jump. */
10473+
/* Fuse load-immediate with a dependent conditional branch. */
10474+
if (get_attr_type (prev) == TYPE_MOVE
10475+
&& get_attr_move_type (prev) == MOVE_TYPE_CONST
10476+
&& any_condjump_p (curr))
10477+
{
10478+
rtx comp = XEXP (SET_SRC (curr_set), 0);
10479+
10480+
return (REG_P (XEXP (comp, 0)) && XEXP (comp, 0) == SET_DEST (prev_set))
10481+
|| (REG_P (XEXP (comp, 1)) && XEXP (comp, 1) == SET_DEST (prev_set));
10482+
}
10483+
10484+
/* Don't handle anything with a jump past this point. */
1047410485
if (!simple_sets_p)
1047510486
return false;
1047610487

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -mtune=arc-v-rhx-100-series" } */
3+
4+
int
5+
f (int x)
6+
{
7+
begin:
8+
if (x <= 3)
9+
goto begin;
10+
}
11+
12+
/* { dg-final { scan-assembler "\\sli\\sa5,3\n\\sble\\sa0,a5,.L\[0-9\]+\n" } } */

0 commit comments

Comments
 (0)