https://gcc.gnu.org/g:1d9e02bb7e0af4f3d3eaaa1a0f4961970aba5560

commit r15-9514-g1d9e02bb7e0af4f3d3eaaa1a0f4961970aba5560
Author: Kito Cheng <kito.ch...@sifive.com>
Date:   Mon Apr 14 16:03:07 2025 +0800

    RISC-V: Put jump table in text for large code model
    
    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.

Diff:
---
 gcc/config/riscv/riscv.h                           |  2 +-
 .../gcc.target/riscv/jump-table-large-code-model.c | 24 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 2bcabd03517a..2759a4cb1c9f 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 000000000000..1ee7f6c07d3d
--- /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" } } */

Reply via email to