re PR rtl-optimization/12799 (faulty mov->add change clobbers the CC register)
authorEric Botcazou <ebotcazou@libertysurf.fr>
Sun, 2 Nov 2003 08:32:23 +0000 (09:32 +0100)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Sun, 2 Nov 2003 08:32:23 +0000 (08:32 +0000)
PR optimization/12799
* postreload.c (reload_cse_move2add): Generate the add2
patterns manually.

From-SVN: r73195

gcc/ChangeLog
gcc/postreload.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20031102-1.c [new file with mode: 0644]

index 01a5a567b5943795cff9403d7bad0fbcd6ad5239..515b5900703e2e2885ec7e96c12332a9cd73f065 100644 (file)
@@ -1,3 +1,9 @@
+2003-11-02  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       PR optimization/12799
+       * postreload.c (reload_cse_move2add): Generate the add2
+       patterns manually.
+
 2003-11-02  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * config/sparc/sparc.c (function_arg_partial_nregs) [TARGET_ARCH64]:
index 362b50ebc13433f009f4fc62076a09550d0095f6..b55c4476f2dbdf49aab245431becd0d6bfc1e15c 100644 (file)
@@ -1199,14 +1199,12 @@ reload_cse_move2add (rtx first)
                  else if (rtx_cost (new_src, PLUS) < rtx_cost (src, SET)
                           && have_add2_insn (reg, new_src))
                    {
-                     rtx newpat = gen_add2_insn (reg, new_src);
-                     if (INSN_P (newpat) && NEXT_INSN (newpat) == NULL_RTX)
-                       newpat = PATTERN (newpat);
-                     /* If it was the first insn of a sequence or
-                        some other emitted insn, validate_change will
-                        reject it.  */
-                     validate_change (insn, &PATTERN (insn),
-                                      newpat, 0);
+                     rtx newpat = gen_rtx_SET (VOIDmode,
+                                               reg,
+                                               gen_rtx_PLUS (GET_MODE (reg),
+                                                             reg,
+                                                             new_src));
+                     validate_change (insn, &PATTERN (insn), newpat, 0);
                    }
                  else
                    {
@@ -1288,10 +1286,11 @@ reload_cse_move2add (rtx first)
                                < COSTS_N_INSNS (1) + rtx_cost (src3, SET))
                               && have_add2_insn (reg, new_src))
                        {
-                         rtx newpat = gen_add2_insn (reg, new_src);
-                         if (INSN_P (newpat)
-                             && NEXT_INSN (newpat) == NULL_RTX)
-                           newpat = PATTERN (newpat);
+                         rtx newpat = gen_rtx_SET (VOIDmode,
+                                                   reg,
+                                                   gen_rtx_PLUS (GET_MODE (reg),
+                                                                 reg,
+                                                                 new_src));
                          success
                            = validate_change (next, &PATTERN (next),
                                               newpat, 0);
index 599563b14f27a7682cc0c74fc13217b987519f5d..be2cc850cf2e36c12c403d865388babc43c82d2d 100644 (file)
@@ -1,3 +1,7 @@
+2003-11-02  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       * gcc.dg/20031102-1.c: New test.
+
 2003-11-02  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * gcc.dg/complex-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/20031102-1.c b/gcc/testsuite/gcc.dg/20031102-1.c
new file mode 100644 (file)
index 0000000..4da4e6a
--- /dev/null
@@ -0,0 +1,37 @@
+/* PR optimization/12799 */
+/* Origin: Pratap Subrahmanyam <pratap@vmware.com> */
+
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+/* { dg-options "-O2 -march=i686" { target i686-*-* } } */
+
+/* Verify that reload_cse_move2add doesn't add unexpected CLOBBERs. */
+
+extern void abort(void);
+
+int loo = 1;
+
+__inline__ char InlineFunc(void)
+{
+  return __builtin_expect(!!(loo == 1), 1);
+}
+
+int FooBar(void)
+{
+  int i;
+  int var1 = InlineFunc() ? 2046 : 1023;
+  int var2 = InlineFunc() ? 512 : 1024;
+
+  for (i = 0; i < var1; i++)
+    ;
+
+  if (InlineFunc() && var2 != 512)
+    abort();
+
+  return 0;
+}
+
+int main(void)
+{
+  return FooBar();
+}