Skip to content

Commit 1aa42c1

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 6e9d52c commit 1aa42c1

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
@@ -827,6 +827,7 @@ extern unsigned int th_int_get_save_adjustment (void);
827827
extern rtx th_int_adjust_cfi_prologue (unsigned int);
828828
extern const char *th_asm_output_opcode (FILE *asm_out_file, const char *p);
829829

830+
extern bool riscv_macro_fusion_p ();
830831
extern bool riscv_is_micro_arch (enum riscv_microarchitecture_type);
831832

832833
#ifdef RTX_CODE

gcc/config/riscv/riscv.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10951,7 +10951,7 @@ riscv_sched_reorder (FILE *, int, rtx_insn **ready, int *nreadyp, int)
1095110951
/* Implement TARGET_SCHED_MACRO_FUSION_P. Return true if target supports
1095210952
instruction fusion of some sort. */
1095310953

10954-
static bool
10954+
bool
1095510955
riscv_macro_fusion_p (void)
1095610956
{
1095710957
return tune_param->fusible_ops != RISCV_FUSE_NOTHING;
@@ -11097,7 +11097,18 @@ arcv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr)
1109711097
/* prev and curr are simple SET insns i.e. no flag setting or branching. */
1109811098
bool simple_sets_p = prev_set && curr_set && !any_condjump_p (curr);
1109911099

11100-
/* Don't handle anything with a jump. */
11100+
/* Fuse load-immediate with a dependent conditional branch. */
11101+
if (get_attr_type (prev) == TYPE_MOVE
11102+
&& get_attr_move_type (prev) == MOVE_TYPE_CONST
11103+
&& any_condjump_p (curr))
11104+
{
11105+
rtx comp = XEXP (SET_SRC (curr_set), 0);
11106+
11107+
return (REG_P (XEXP (comp, 0)) && XEXP (comp, 0) == SET_DEST (prev_set))
11108+
|| (REG_P (XEXP (comp, 1)) && XEXP (comp, 1) == SET_DEST (prev_set));
11109+
}
11110+
11111+
/* Don't handle anything with a jump past this point. */
1110111112
if (!simple_sets_p)
1110211113
return false;
1110311114

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)