As Maciej reports in PR 74563, we currently generate incorrect code for mips16 (classic) non-leaf function returns.

Specifically we sometimes generate jr $31, when we should be generating jr $7 (and there are times when we want to generate jr $31).

The problem as Maciej and I independently concluded was the bogus assignment to operands[0] in the {return,simple_return}_internal pattern. That pattern accepts the return pointer register as an argument and AFAICT mips.c passes the right return pointer register consistently. Overwriting that operand is just pointless and wrong.

This patch removes the bogus assignment and adds a suitable testcase. Tested by verifying my MIPS configurations can build newlib/glibc as appropriate. Also tested the testcase using mips64vr-elf cross compiler.

Installing on the trunk.

Jeff
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ea44ddb553e..7aa8c03c45b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-04-18  Jeff Law  <l...@redhat.com>
+
+       PR target/74563
+       * mips.md ({return,simple_return}_internal): Do not overwrite
+       operands[0].
+
 2017-04-18  Jakub Jelinek  <ja...@redhat.com>
 
        PR tree-optimization/80443
diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md
index 7acf00d0451..28e0a444ba9 100644
--- a/gcc/config/mips/mips.md
+++ b/gcc/config/mips/mips.md
@@ -6585,7 +6585,6 @@
    (use (match_operand 0 "pmode_register_operand" ""))]
   ""
   {
-    operands[0] = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
     return mips_output_jump (operands, 0, -1, false);
   }
   [(set_attr "type"    "jump")
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 11410bb7045..c21e3733ed4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-04-18  Jeff Law  <l...@redhat.com>
+
+       PR target/74563
+       * gcc.target/mips/pr74563: New test.
+
 2017-04-18  Jakub Jelinek  <ja...@redhat.com>
 
        PR tree-optimization/80443
diff --git a/gcc/testsuite/gcc.target/mips/pr74563.c 
b/gcc/testsuite/gcc.target/mips/pr74563.c
new file mode 100644
index 00000000000..09545fcb5bd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/pr74563.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-mips3 -mips16 -msoft-float" } */
+
+void f2(void);
+
+void f1(void)
+{
+        f2();
+}
+
+/* { dg-final { scan-assembler-not "\tjr\t\\\$31" } } */
+/* { dg-final { scan-assembler "\tjr\t\\\$7" } } */
+
+

Reply via email to