public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/PR93274-make-resolver-static-v2)] RISC-V: Disallow regrenme if the TO register never used before for interrupt functions
@ 2020-01-27 10:03 Martin Liska
0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2020-01-27 10:03 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e0a5b313c1a3edfb33a28b8d8fea92e01490ebb3
commit e0a5b313c1a3edfb33a28b8d8fea92e01490ebb3
Author: Kito Cheng <kito.cheng@sifive.com>
Date: Fri Jan 17 19:49:15 2020 +0800
RISC-V: Disallow regrenme if the TO register never used before for interrupt functions
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.
Diff:
---
gcc/ChangeLog | 7 +++++++
gcc/config/riscv/riscv-protos.h | 2 ++
gcc/config/riscv/riscv.c | 13 +++++++++++++
gcc/config/riscv/riscv.h | 2 ++
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/gcc.target/riscv/pr93304.c | 19 +++++++++++++++++++
6 files changed, 48 insertions(+)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 31b7305..0581561 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+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-20 Wilco Dijkstra <wdijkstr@arm.com>
* config/aarch64/aarch64.c (neoversen1_tunings): Set jump_align to 4.
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 26b8110..8cf9137 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -89,4 +89,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 */
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 320a70b..5730240 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -5021,6 +5021,19 @@ riscv_reorg (void)
riscv_remove_unneeded_save_restore_calls ();
}
+/* 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"
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 0bf3d2f..19438e2 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -926,4 +926,6 @@ extern unsigned riscv_stack_boundary;
extern void riscv_remove_unneeded_save_restore_calls (void);
+#define HARD_REGNO_RENAME_OK(FROM, TO) riscv_hard_regno_rename_ok (FROM, TO)
+
#endif /* ! GCC_RISCV_H */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 452c16e..fa457c8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-01-21 Kito Cheng <kito.cheng@sifive.com>
+
+ PR target/93304
+ * gcc.target/riscv/pr93304.c: New test.
+
2020-01-20 Martin Sebor <msebor@redhat.com>
PR testsuite/92829
diff --git a/gcc/testsuite/gcc.target/riscv/pr93304.c b/gcc/testsuite/gcc.target/riscv/pr93304.c
new file mode 100644
index 0000000..f771e48
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr93304.c
@@ -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\]" } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-01-27 10:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-27 10:03 [gcc(refs/users/marxin/heads/PR93274-make-resolver-static-v2)] RISC-V: Disallow regrenme if the TO register never used before for interrupt functions Martin Liska
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).