]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Disallow regrenme if the TO register never used before for interrupt functions
authorKito Cheng <kito.cheng@sifive.com>
Fri, 17 Jan 2020 11:49:15 +0000 (19:49 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Thu, 30 Jan 2020 07:33:07 +0000 (15:33 +0800)
gcc/ChangeLog

PR target/93304
* config/riscv/riscv-protos.h (riscv_hard_regno_rename_ok): New.
* config/riscv/riscv.c (riscv_hard_regno_rename_ok): New.
* config/riscv/riscv.h (HARD_REGNO_RENAME_OK): Defined.

gcc/testsuite/ChangeLog

PR target/93304
* gcc.target/riscv/pr93304.c: New test.

gcc/ChangeLog
gcc/config/riscv/riscv-protos.h
gcc/config/riscv/riscv.c
gcc/config/riscv/riscv.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/riscv/pr93304.c [new file with mode: 0644]

index 4e84692926f6cdc9ec31112e4db6c07850071c84..524dd981a6b5ca96937e67ca9a6848a918c8a7f8 100644 (file)
@@ -1,3 +1,13 @@
+2020-01-30  Kito Cheng  <kito.cheng@sifive.com>
+
+       Backport from mainline
+       2020-01-21  Kito Cheng  <kito.cheng@sifive.com>
+
+       PR target/93304
+       * config/riscv/riscv-protos.h (riscv_hard_regno_rename_ok): New.
+       * config/riscv/riscv.c (riscv_hard_regno_rename_ok): New.
+       * config/riscv/riscv.h (HARD_REGNO_RENAME_OK): Defined.
+
 2020-01-29  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
        Backport from mainline
index 5b0bbdd7cb4ec15883905b6b651aba35058a19fb..1bfc65e6d9fa89922d57123f069d12ded16ca7af 100644 (file)
@@ -88,4 +88,6 @@ extern void riscv_init_builtins (void);
 /* Routines implemented in riscv-common.c.  */
 extern std::string riscv_arch_str ();
 
+extern bool riscv_hard_regno_rename_ok (unsigned, unsigned);
+
 #endif /* ! GCC_RISCV_PROTOS_H */
index 931662b31371796bb91b7992f7c7a0d861952339..b3297a38114fb26764d7b17908dcfab12727c1c4 100644 (file)
@@ -4907,6 +4907,19 @@ riscv_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
   return mode;
 }
 
+/* Return nonzero if register FROM_REGNO can be renamed to register
+   TO_REGNO.  */
+
+bool
+riscv_hard_regno_rename_ok (unsigned from_regno ATTRIBUTE_UNUSED,
+                           unsigned to_regno)
+{
+  /* Interrupt functions can only use registers that have already been
+     saved by the prologue, even if they would normally be
+     call-clobbered.  */
+  return !cfun->machine->interrupt_handler_p || df_regs_ever_live_p (to_regno);
+}
+
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_ALIGNED_HI_OP
 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
index c93743f95498506c67f485cb2376bfc90e752a43..5130dc826d78a8241e3d32895fb4367df36025a3 100644 (file)
@@ -908,4 +908,6 @@ extern unsigned riscv_stack_boundary;
 #define SWSP_REACH (4LL << C_SxSP_BITS)
 #define SDSP_REACH (8LL << C_SxSP_BITS)
 
+#define HARD_REGNO_RENAME_OK(FROM, TO) riscv_hard_regno_rename_ok (FROM, TO)
+
 #endif /* ! GCC_RISCV_H */
index f17f7f44a2e370efe04811c7f457f5cd25a5743e..9e117a6854a18cbaf80625c8d0604e4afbe20076 100644 (file)
@@ -1,3 +1,11 @@
+2020-01-30  Kito Cheng  <kito.cheng@sifive.com>
+
+       Backport from mainline
+       2020-01-21  Kito Cheng  <kito.cheng@sifive.com>
+
+       PR target/93304
+       * gcc.target/riscv/pr93304.c: New test.
+
 2020-01-29  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.target/riscv/pr93304.c b/gcc/testsuite/gcc.target/riscv/pr93304.c
new file mode 100644 (file)
index 0000000..f771e48
--- /dev/null
@@ -0,0 +1,19 @@
+/* Verify the regrename won't rename registers to register which never used
+   before.  */
+/* { dg-do compile } */
+/* { dg-options "-O -frename-registers" } */
+
+static unsigned _t = 0;
+
+void __attribute__ ((interrupt))
+foo (void)
+{
+  _t++;
+}
+
+/* Register rename will try to use registers from the lower register
+   regradless of the REG_ALLOC_ORDER.
+   In theory, t0-t6 should not used in such small program if regrename
+   not executed incorrectly, because a5-a0 has higher priority in
+   REG_ALLOC_ORDER.  */
+/* { dg-final { scan-assembler-not "t\[0-6\]" } } */