diff mbox

[arm-embedded,committed] PR78255: Make postreload aware of NO_FUNCTION_CSE

Message ID 584AE858.5020706@arm.com
State New
Headers show

Commit Message

Andre Vieira (lists) Dec. 9, 2016, 5:22 p.m. UTC
Hi

I backported this patch to the embedded-6-branch in revision r243496.

Cheers,
Andre

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

	Backport from mainline
	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.arm:
2016-12-09  Andre Vieira  <andre.simoesdiasvieira@arm.com>

	Backport from mainline
	2016-12-09  Andre Vieira <andre.simoesdiasvieira@arm.com>

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

Patch

diff --git a/gcc/ChangeLog.arm b/gcc/ChangeLog.arm
index 501388026dc76edb195a783d458d2dab538733f8..3b68af407f78320b465951591c2eba9d27fec944 100644
--- a/gcc/ChangeLog.arm
+++ b/gcc/ChangeLog.arm
@@ -1,3 +1,12 @@ 
+2016-12-09  Andre Vieira  <andre.simoesdiasvieira@arm.com>
+
+	Backport from mainline
+	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.
+
 2016-12-07  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
 	Backport from mainline
diff --git a/gcc/postreload.c b/gcc/postreload.c
index 61c1ce8028e3d8e6cab44f8f36be31fdc8a58f71..311b83019602dd4aa8289fba776a3f16f4340c6f 100644
--- a/gcc/postreload.c
+++ b/gcc/postreload.c
@@ -93,6 +93,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/ChangeLog.arm b/gcc/testsuite/ChangeLog.arm
index d81eaaf9eed3b63ec6403bf4229bd5e4c343063f..af426611d47fc4d134c699580025ca0c58e8903a 100644
--- a/gcc/testsuite/ChangeLog.arm
+++ b/gcc/testsuite/ChangeLog.arm
@@ -1,3 +1,13 @@ 
+2016-12-09  Andre Vieira  <andre.simoesdiasvieira@arm.com>
+
+	Backport from mainline
+	2016-12-09  Andre Vieira <andre.simoesdiasvieira@arm.com>
+
+	PR rtl-optimization/78255
+	* gcc.target/aarch64/pr78255.c: New.
+	* gcc.target/arm/pr78255-1.c: New.
+	* gcc.target/arm/pr78255-2.c: New.
+
 2016-12-07  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
 	Backport from mainline
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..5a696825295d18d09822edfc48f211c5712e95bb
--- /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..efa01e750b3962497cccb05ab9862fd3935397a3
--- /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" } } */