This patch will be committed this week if CI passes and not strong
objections since it's bug to large code model, also change is small

On Mon, Apr 14, 2025 at 6:00 PM Kito Cheng <kito.ch...@sifive.com> wrote:
>
> Large code model assume the data or rodata may put far away from
> text section.  So we need to put jump table in text section for
> large code model.
>
> gcc/ChangeLog:
>
>         * config/riscv/riscv.h (JUMP_TABLES_IN_TEXT_SECTION): Check if
>         large code model.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/jump-table-large-code-model.c: New test.
> ---
>  gcc/config/riscv/riscv.h                      |  2 +-
>  .../riscv/jump-table-large-code-model.c       | 24 +++++++++++++++++++
>  2 files changed, 25 insertions(+), 1 deletion(-)
>  create mode 100644 
> gcc/testsuite/gcc.target/riscv/jump-table-large-code-model.c
>
> diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
> index 2bcabd03517..2759a4cb1c9 100644
> --- a/gcc/config/riscv/riscv.h
> +++ b/gcc/config/riscv/riscv.h
> @@ -888,7 +888,7 @@ extern enum riscv_cc get_riscv_cc (const rtx use);
>  #define ASM_OUTPUT_OPCODE(STREAM, PTR) \
>    (PTR) = riscv_asm_output_opcode(STREAM, PTR)
>
> -#define JUMP_TABLES_IN_TEXT_SECTION 0
> +#define JUMP_TABLES_IN_TEXT_SECTION (riscv_cmodel == CM_LARGE)
>  #define CASE_VECTOR_MODE SImode
>  #define CASE_VECTOR_PC_RELATIVE (riscv_cmodel != CM_MEDLOW)
>
> diff --git a/gcc/testsuite/gcc.target/riscv/jump-table-large-code-model.c 
> b/gcc/testsuite/gcc.target/riscv/jump-table-large-code-model.c
> new file mode 100644
> index 00000000000..1ee7f6c07d3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/jump-table-large-code-model.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64gc -mabi=lp64 -mcmodel=large" } */
> +
> +int foo(int x, int y)
> +{
> +  switch(x){
> +  case 0:
> +    return 123 + y;
> +  case 1:
> +    return 456 + y;
> +  case 2:
> +    return 789 - y;
> +  case 3:
> +    return 12 * y;
> +  case 4:
> +    return 13 % y;
> +  case 5:
> +    return 11 *y;
> +  }
> +  return 0;
> +}
> +
> +
> +/* { dg-final { scan-assembler-not "\.section  \.rodata" } } */
> --
> 2.34.1
>

Reply via email to