re PR middle-end/32897 (Invalid rematerialisation of subregs)
authorRichard Sandiford <richard@codesourcery.com>
Thu, 16 Aug 2007 10:16:15 +0000 (10:16 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 16 Aug 2007 10:16:15 +0000 (10:16 +0000)
gcc/
PR middle-end/32897
* reload.c (find_reloads): Check that the memory returned by
find_reloads_toplev was not the result of forcing a constant
to memory.
(find_reloads_toplev): Always use simplify_gen_subreg to get
the subreg of a constant.  If the result is also a constant,
but not a legitimate one, force it into the constant pool
and reload its address.

gcc/testsuite/
* gcc.dg/torture/pr32897.c: New test.

From-SVN: r127536

gcc/ChangeLog
gcc/reload.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr32897.c [new file with mode: 0644]

index 0629abd..2a5d7f5 100644 (file)
@@ -1,3 +1,14 @@
+2007-08-16  Richard Sandiford  <richard@codesourcery.com>
+
+       PR middle-end/32897
+       * reload.c (find_reloads): Check that the memory returned by
+       find_reloads_toplev was not the result of forcing a constant
+       to memory.
+       (find_reloads_toplev): Always use simplify_gen_subreg to get
+       the subreg of a constant.  If the result is also a constant,
+       but not a legitimate one, force it into the constant pool
+       and reload its address.
+
 2007-08-15  David Edelsohn  <edelsohn@gnu.org>
 
        * config/rs6000/rs6000.c (rs6000_rtx_costs): Add CLZ, CTZ, and
index ae913bf..06ce96b 100644 (file)
@@ -2794,7 +2794,8 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known,
              && MEM_P (op)
              && REG_P (reg)
              && (GET_MODE_SIZE (GET_MODE (reg))
-                 >= GET_MODE_SIZE (GET_MODE (op))))
+                 >= GET_MODE_SIZE (GET_MODE (op)))
+             && reg_equiv_constant[REGNO (reg)] == 0)
            set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
                                                   insn),
                                 REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]);
@@ -4600,14 +4601,6 @@ find_reloads_toplev (rtx x, int opnum, enum reload_type type,
       int regno = REGNO (SUBREG_REG (x));
       rtx tem;
 
-      if (subreg_lowpart_p (x)
-         && regno >= FIRST_PSEUDO_REGISTER
-         && reg_renumber[regno] < 0
-         && reg_equiv_constant[regno] != 0
-         && (tem = gen_lowpart_common (GET_MODE (x),
-                                       reg_equiv_constant[regno])) != 0)
-       return tem;
-
       if (regno >= FIRST_PSEUDO_REGISTER
          && reg_renumber[regno] < 0
          && reg_equiv_constant[regno] != 0)
@@ -4616,6 +4609,15 @@ find_reloads_toplev (rtx x, int opnum, enum reload_type type,
            simplify_gen_subreg (GET_MODE (x), reg_equiv_constant[regno],
                                 GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
          gcc_assert (tem);
+         if (CONSTANT_P (tem) && !LEGITIMATE_CONSTANT_P (tem))
+           {
+             tem = force_const_mem (GET_MODE (x), tem);
+             i = find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
+                                       &XEXP (tem, 0), opnum, type,
+                                       ind_levels, insn);
+             if (address_reloaded)
+               *address_reloaded = i;
+           }
          return tem;
        }
 
index 14e58c9..0b79ae9 100644 (file)
@@ -1,3 +1,7 @@
+2007-08-16  Richard Sandiford  <richard@codesourcery.com>
+
+       * gcc.dg/torture/pr32897.c: New test.
+
 2007-08-16  Paolo Carlini  <pcarlini@suse.de>
 
        PR c++/31132
diff --git a/gcc/testsuite/gcc.dg/torture/pr32897.c b/gcc/testsuite/gcc.dg/torture/pr32897.c
new file mode 100644 (file)
index 0000000..3dc43ec
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-options "-G0" { target mips*-*-* } } */
+
+volatile int g[32];
+long long gll;
+double gd;
+
+#define MULTI(X) \
+       X( 1), X( 2), X( 3), X( 4), X( 5), X( 6), X( 7), X( 8), X( 9), X(10), \
+       X(11), X(12), X(13), X(14), X(15), X(16), X(17), X(18), X(19), X(20), \
+       X(21), X(22), X(23), X(24), X(25), X(26), X(27), X(28), X(29), X(30)
+
+#define DECLARE(INDEX) x##INDEX
+#define COPY_IN(INDEX) x##INDEX = g[INDEX]
+#define COPY_OUT(INDEX) g[INDEX] = x##INDEX
+
+void
+test (int n)
+{
+  union { long long l; double d; } u = { 0x12345678 };
+  gll = u.l;
+  int MULTI (DECLARE);
+  MULTI (COPY_IN);
+  MULTI (COPY_OUT);
+  MULTI (COPY_OUT);
+  MULTI (COPY_OUT);
+  gd = u.d;
+}