public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR78255: Make postreload aware of NO_FUNCTION_CSE
@ 2016-12-09 14:03 Andre Vieira (lists)
  2016-12-09 15:02 ` Bernd Schmidt
  0 siblings, 1 reply; 15+ messages in thread
From: Andre Vieira (lists) @ 2016-12-09 14:03 UTC (permalink / raw)
  To: GCC Patches

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

Hi,

This patch fixes the issue reported in PR78255 by making postreload
aware it should not be performing CSE on functions if NO_FUNCTION_CSE is
defined to true.

Bootstrap and full regression on arm-none-linux-gnueabihf and
aarch64-unknown-linux-gnu.

Also checked this fixed the reported issue on arm-none-eabi.

Is this OK for trunk?

Cheers,
Andre

gcc/ChangeLog
2016-12-09  Andre Vieira <andre.simoesdiasvieira@arm.com>

        PR rtl-optimization/78255
        * gcc/postreload.c (reload_cse_simplify): Do not CSE a function if
        NO_FUNCTION_CSE is true.

gcc/testsuite/ChangeLog:
2016-12-09  Andre Vieira <andre.simoesdiasvieira@arm.com>

        PR rtl-optimization/78255
        * gcc.target/arm/pr78255-1.c: New.
        * gcc.target/arm/pr78255-2.c: New.


gcc/testsuite/ChangeLog:
2016-12-09  Andre Vieira <andre.simoesdiasvieira@arm.com>

        PR rtl-optimization/78255
        * gcc.target/aarch64/pr78255.c: New.

[-- Attachment #2: diff --]
[-- Type: text/plain, Size: 2935 bytes --]

diff --git a/gcc/postreload.c b/gcc/postreload.c
index 539ad33b6c3eb1b968677419a7420badc3a52f01..8325d121c403786fdb7804956724a81d134252a2 100644
--- a/gcc/postreload.c
+++ b/gcc/postreload.c
@@ -90,6 +90,11 @@ reload_cse_simplify (rtx_insn *insn, rtx testreg)
   basic_block insn_bb = BLOCK_FOR_INSN (insn);
   unsigned insn_bb_succs = EDGE_COUNT (insn_bb->succs);
 
+  /* If NO_FUNCTION_CSE has been set by the target, then we should not try
+     to cse function calls.  */
+  if (NO_FUNCTION_CSE && CALL_P (insn))
+    return false;
+
   if (GET_CODE (body) == SET)
     {
       int count = 0;
diff --git a/gcc/testsuite/gcc.target/aarch64/pr78255.c b/gcc/testsuite/gcc.target/aarch64/pr78255.c
new file mode 100644
index 0000000000000000000000000000000000000000..b078cf3e1c1c7717c9e227721a367f9846f0c7fe
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr78255.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcmodel=tiny" } */
+
+extern int bar (void *);
+
+int
+foo (void)
+{
+  return bar ((void *)bar);
+}
+
+/* { dg-final { scan-assembler "b\\s+bar" } } */
diff --git a/gcc/testsuite/gcc.target/arm/pr78255-1.c b/gcc/testsuite/gcc.target/arm/pr78255-1.c
new file mode 100644
index 0000000000000000000000000000000000000000..4901acea51466c0bac92d9cb90e52b00b450d88a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/pr78255-1.c
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+/* { dg-options "-O2" }  */
+
+#include <string.h>
+
+struct table_s
+    {
+    void (*fun0)
+        ( void );
+    void (*fun1)
+        ( void );
+    void (*fun2)
+        ( void );
+    void (*fun3)
+        ( void );
+    void (*fun4)
+        ( void );
+    void (*fun5)
+        ( void );
+    void (*fun6)
+        ( void );
+    void (*fun7)
+        ( void );
+    } table;
+
+void callback0(){__asm("mov r0, r0 \n\t");}
+void callback1(){__asm("mov r0, r0 \n\t");}
+void callback2(){__asm("mov r0, r0 \n\t");}
+void callback3(){__asm("mov r0, r0 \n\t");}
+void callback4(){__asm("mov r0, r0 \n\t");}
+
+void test (void) {
+    memset(&table, 0, sizeof table);
+
+    asm volatile ("" : : : "r3");
+
+    table.fun0 = callback0;
+    table.fun1 = callback1;
+    table.fun2 = callback2;
+    table.fun3 = callback3;
+    table.fun4 = callback4;
+    table.fun0();
+}
+
+void foo (void)
+{
+  __builtin_abort ();
+}
+
+int main (void)
+{
+  unsigned long p = (unsigned long) &foo;
+  asm volatile ("mov r3, %0" : : "r" (p));
+  test ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/pr78255-2.c b/gcc/testsuite/gcc.target/arm/pr78255-2.c
new file mode 100644
index 0000000000000000000000000000000000000000..9e64ef3939465b088e35a01d4bb23fd50d43006d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/pr78255-2.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" }  */
+
+extern int bar (void *);
+
+int
+foo (void)
+{
+  return bar ((void*)bar);
+}
+
+/* { dg-final { scan-assembler "b\\s+bar" } } */

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH] PR78255: Make postreload aware of NO_FUNCTION_CSE
@ 2016-12-09 15:47 Wilco Dijkstra
  0 siblings, 0 replies; 15+ messages in thread
From: Wilco Dijkstra @ 2016-12-09 15:47 UTC (permalink / raw)
  To: GCC Patches, Bernd Edlinger; +Cc: nd, Andre Simoes Dias Vieira

Bernd wrote:

> Hmm, it probably doesn't hurt, but looking at the PR I think the originally reported problem 
> suggests you need a different fix: a separate register class to be used for indirect sibling calls. 
> I remember seeing similar issues on other targets. 

The only safe way to block any changes between direct and indirect calls is to split
them into separate instructions (rather than have 2 alternatives).  That's a good idea
to do anyway as calls already do this, so tailcalls should follow the same pattern.

However this patch fixes the postreload issue for all targets, similarly my leaf_function
patches fix any latent issues in prolog/epilog generation across all targets.

Wilco

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

end of thread, other threads:[~2017-01-11 15:09 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-09 14:03 [PATCH] PR78255: Make postreload aware of NO_FUNCTION_CSE Andre Vieira (lists)
2016-12-09 15:02 ` Bernd Schmidt
2016-12-09 15:34   ` Andre Vieira (lists)
2016-12-09 15:58     ` Bernd Schmidt
2016-12-09 16:02       ` Ramana Radhakrishnan
2016-12-09 16:16         ` Andre Vieira (lists)
2016-12-09 16:31           ` Bernd Schmidt
2016-12-09 17:22             ` [arm-embedded][committed] " Andre Vieira (lists)
2017-01-06 10:53             ` [PATCH] " Andre Vieira (lists)
2017-01-06 15:47               ` Jeff Law
2017-01-11 15:09                 ` Andre Vieira (lists)
2016-12-12  9:05           ` Christophe Lyon
2016-12-20 16:48             ` [ARM][committed] Fix for PR78255-2.c testism for targets that do not optimize for tailcall Andre Vieira (lists)
2016-12-09 16:01   ` [PATCH] PR78255: Make postreload aware of NO_FUNCTION_CSE Jeff Law
2016-12-09 15:47 Wilco Dijkstra

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