This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix loop unswitching (PR rtl-optimization/21330)


Hi!

The testcase below ICEs on powerpc{,64}-linux at -O3.

compare_and_jump_seq uses asserts to make sure cinsn is non-NULL
iff comparision is in CC mode:
  if (GET_MODE_CLASS (mode) == MODE_CC)
    {
      /* A hack -- there seems to be no easy generic way how to make a
         conditional jump from a ccmode comparison.  */
      gcc_assert (cinsn);
...
  else
    {
      gcc_assert (!cinsn);
...
    }

but may_unswitch_on sometimes returns NULL but sets *cinsn anyway:
  if (GET_MODE_CLASS (mode) == MODE_CC)
    {
      if (at != BB_END (bb))
        return NULL_RTX;

      *cinsn = BB_END (bb);
      if (!rtx_equal_p (op[0], XEXP (test, 0))
          || !rtx_equal_p (op[1], XEXP (test, 1)))
        return NULL_RTX;

      return test;
    }
and even if it did not do this, nothing clears it if the loop
is repeated.

Bootstrapped/regtested on powerpc64-linux, ok to commit?
4.0 as well?

Alternatively, we could move the
*cinsn = BB_END (bb);
right before return test; and cinsn = NULL_RTX; below
repeat = 0; in unswitch_single_loop.

2005-05-02  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/21330
	* loop-unswitch.c (may_unswitch_on): Clear *cinsn.

	* gcc.c-torture/execute/20050502-1.c: New test.

--- gcc/loop-unswitch.c.jj	2005-04-04 13:06:28.000000000 +0200
+++ gcc/loop-unswitch.c	2005-05-02 12:17:55.000000000 +0200
@@ -177,6 +177,8 @@ may_unswitch_on (basic_block bb, struct 
   unsigned i;
   enum machine_mode mode;
 
+  *cinsn = NULL_RTX;
+
   /* BB must end in a simple conditional jump.  */
   if (EDGE_COUNT (bb->succs) != 2)
     return NULL_RTX;
--- gcc/testsuite/gcc.c-torture/execute/20050502-1.c.jj	2005-05-02 12:36:01.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/execute/20050502-1.c	2005-05-02 12:35:39.000000000 +0200
@@ -0,0 +1,67 @@
+/* PR rtl-optimization/21330 */
+
+extern void abort (void);
+extern int strcmp (const char *, const char *);
+
+int
+__attribute__((noinline))
+bar (const char **x)
+{
+  return *(*x)++;
+}
+
+int
+__attribute__((noinline))
+baz (int c)
+{
+  return c != '@';
+}
+
+void
+__attribute__((noinline))
+foo (const char **w, char *x, _Bool y, _Bool z)
+{
+  char c = bar (w);
+  int i = 0;
+
+  while (1)
+    {
+      x[i++] = c;
+      c = bar (w);
+      if (y && c == '\'')
+        break;
+      if (z && c == '\"')
+        break;
+      if (!y && !z && !baz (c))
+        break;
+    }
+   x[i] = 0;
+}
+
+int
+main (void)
+{
+  char buf[64];
+  const char *p;
+  p = "abcde'fgh";
+  foo (&p, buf, 1, 0);
+  if (strcmp (p, "fgh") != 0 || strcmp (buf, "abcde") != 0)
+    abort ();
+  p = "ABCDEFG\"HI";
+  foo (&p, buf, 0, 1);
+  if (strcmp (p, "HI") != 0 || strcmp (buf, "ABCDEFG") != 0)
+    abort ();
+  p = "abcd\"e'fgh";
+  foo (&p, buf, 1, 1);
+  if (strcmp (p, "e'fgh") != 0 || strcmp (buf, "abcd") != 0)
+    abort ();
+  p = "ABCDEF'G\"HI";
+  foo (&p, buf, 1, 1);
+  if (strcmp (p, "G\"HI") != 0 || strcmp (buf, "ABCDEF") != 0)
+    abort ();
+  p = "abcdef@gh";
+  foo (&p, buf, 0, 0);
+  if (strcmp (p, "gh") != 0 || strcmp (buf, "abcdef") != 0)
+    abort ();
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]