public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][GCC][Arm] PR target/95646: Do not clobber callee saved registers with CMSE
@ 2020-06-22  8:51 Andre Vieira (lists)
  2020-06-23 12:10 ` Kyrylo Tkachov
  0 siblings, 1 reply; 14+ messages in thread
From: Andre Vieira (lists) @ 2020-06-22  8:51 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1431 bytes --]

Hi,

As reported in bugzilla when the -mcmse option is used while compiling 
for size (-Os) with a thumb-1 target the generated code will clear the 
registers r7-r10. These however are callee saved and should be preserved 
accross ABI boundaries. The reason this happens is because these 
registers are made "fixed" when optimising for size with Thumb-1 in a 
way to make sure they are not used, as pushing and popping hi-registers 
requires extra moves to and from LO_REGS.

To fix this, this patch uses 'callee_saved_reg_p', which accounts for 
this optimisation, instead of 'call_used_or_fixed_reg_p'. Be aware of 
'callee_saved_reg_p''s definition, as it does still take call used 
registers into account, which aren't callee_saved in my opinion, so it 
is a rather misnoemer, works in our advantage here though as it does 
exactly what we need.

Regression tested on arm-none-eabi.

Is this OK for trunk? (Will eventually backport to previous versions if 
stable.)

Cheers,
Andre

gcc/ChangeLog:
2020-06-22  Andre Vieira  <andre.simoesdiasvieira@arm.com>

         PR target/95646
         * config/arm/arm.c: (cmse_nonsecure_entry_clear_before_return): 
Use 'callee_saved_reg_p' instead of
         'calL_used_or_fixed_reg_p'.

gcc/testsuite/ChangeLog:
2020-06-22  Andre Vieira  <andre.simoesdiasvieira@arm.com>

         PR target/95646
         * gcc.target/arm/pr95646.c: New test.


[-- Attachment #2: cmse_thumb1_os.patch --]
[-- Type: text/plain, Size: 1342 bytes --]

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 6b7ca829f1c8cbe3d427da474b079882dc522e1a..dac9a6fb5c41ce42cd7a278b417eab25239a043c 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -26960,7 +26960,7 @@ cmse_nonsecure_entry_clear_before_return (void)
 	continue;
       if (IN_RANGE (regno, IP_REGNUM, PC_REGNUM))
 	continue;
-      if (call_used_or_fixed_reg_p (regno)
+      if (!callee_saved_reg_p (regno)
 	  && (!IN_RANGE (regno, FIRST_VFP_REGNUM, LAST_VFP_REGNUM)
 	      || TARGET_HARD_FLOAT))
 	bitmap_set_bit (to_clear_bitmap, regno);
diff --git a/gcc/testsuite/gcc.target/arm/pr95646.c b/gcc/testsuite/gcc.target/arm/pr95646.c
new file mode 100644
index 0000000000000000000000000000000000000000..c9fdc37618ccaddcdb597647c7076054af17789a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/pr95646.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-mcmse -Os -mcpu=cortex-m23" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+int __attribute__ ((cmse_nonsecure_entry))
+foo (void)
+{
+  return 1;
+}
+/* { { dg-final { scan-assembler-not "mov\tr9, r0" } } */
+
+/*
+** __acle_se_bar:
+**	mov	(r[0-3]), r9
+**	push	{\1}
+** ...
+**	pop	{(r[0-3])}
+**	mov	r9, \2
+** ...
+**	bxns	lr
+*/
+int __attribute__ ((cmse_nonsecure_entry))
+bar (void)
+{
+  asm ("": : : "r9");
+  return 1;
+}

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-08-06  9:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22  8:51 [PATCH][GCC][Arm] PR target/95646: Do not clobber callee saved registers with CMSE Andre Vieira (lists)
2020-06-23 12:10 ` Kyrylo Tkachov
2020-06-23 13:28   ` Andre Vieira (lists)
2020-06-23 13:29     ` Kyrylo Tkachov
2020-06-23 20:52     ` Christophe Lyon
2020-06-29  8:45       ` Andre Vieira (lists)
2020-06-29  8:56       ` Andre Vieira (lists)
2020-06-29 10:15         ` Christophe Lyon
2020-06-30 13:50           ` Andre Vieira (lists)
2020-07-06 14:30             ` Andre Vieira (lists)
2020-07-07 12:43               ` Christophe Lyon
2020-07-08  8:04                 ` Andre Simoes Dias Vieira
2020-07-20 13:33                   ` Andre Vieira (lists)
2020-08-06  9:56               ` Kyrylo Tkachov

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).