[RTL-ifcvt] PR rtl-optimization/68506: Fix emitting order of insns in IF-THEN-JOIN...
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Fri, 27 Nov 2015 09:49:38 +0000 (09:49 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Fri, 27 Nov 2015 09:49:38 +0000 (09:49 +0000)
PR rtl-optimization/68506
* ifcvt.c (noce_try_cmove_arith): Try emitting the else basic block
first if emit_a exists or then_bb modifies 'b'.  Reindent if-else
blocks.

* gcc.c-torture/execute/pr68506.c: New test.

From-SVN: r231003

gcc/ChangeLog
gcc/ifcvt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr68506.c [new file with mode: 0644]

index 24fb40fb90cc3b120c50a79219b8d9ecaf66133e..9278a0c72768e802d224917be62cba1788eb39a7 100644 (file)
@@ -1,3 +1,10 @@
+2015-11-27  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       PR rtl-optimization/68506
+       * ifcvt.c (noce_try_cmove_arith): Try emitting the else basic block
+       first if emit_a exists or then_bb modifies 'b'.  Reindent if-else
+       blocks.
+
 2015-11-27  Martin Liska  <mliska@suse.cz>
 
        PR c++/68312
index fc724bcb890e68c51df74e873348b724378761b0..8ece8734338c38881254c0fe6f71659f807719d3 100644 (file)
@@ -2190,40 +2190,38 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
          }
 
     }
-    if (emit_a && modified_in_a)
-      {
-       modified_in_b = emit_b != NULL_RTX && modified_in_p (orig_a, emit_b);
-       if (tmp_b && else_bb)
-         {
-           FOR_BB_INSNS (else_bb, tmp_insn)
-           /* Don't check inside insn_b.  We will have changed it to emit_b
-              with a destination that doesn't conflict.  */
-             if (!(insn_b && tmp_insn == insn_b)
-                 && modified_in_p (orig_a, tmp_insn))
-               {
-                 modified_in_b = true;
-                 break;
-               }
-
-         }
-       if (modified_in_b)
-         goto end_seq_and_fail;
-
-       if (!noce_emit_bb (emit_b, else_bb, b_simple))
-         goto end_seq_and_fail;
+  if (emit_a || modified_in_a)
+    {
+      modified_in_b = emit_b != NULL_RTX && modified_in_p (orig_a, emit_b);
+      if (tmp_b && else_bb)
+       {
+         FOR_BB_INSNS (else_bb, tmp_insn)
+         /* Don't check inside insn_b.  We will have changed it to emit_b
+            with a destination that doesn't conflict.  */
+         if (!(insn_b && tmp_insn == insn_b)
+             && modified_in_p (orig_a, tmp_insn))
+           {
+             modified_in_b = true;
+             break;
+           }
+       }
+      if (modified_in_b)
+       goto end_seq_and_fail;
 
-       if (!noce_emit_bb (emit_a, then_bb, a_simple))
-         goto end_seq_and_fail;
-      }
-    else
-      {
-       if (!noce_emit_bb (emit_a, then_bb, a_simple))
-         goto end_seq_and_fail;
+      if (!noce_emit_bb (emit_b, else_bb, b_simple))
+       goto end_seq_and_fail;
 
-       if (!noce_emit_bb (emit_b, else_bb, b_simple))
-         goto end_seq_and_fail;
+      if (!noce_emit_bb (emit_a, then_bb, a_simple))
+       goto end_seq_and_fail;
+    }
+  else
+    {
+      if (!noce_emit_bb (emit_a, then_bb, a_simple))
+       goto end_seq_and_fail;
 
-      }
+      if (!noce_emit_bb (emit_b, else_bb, b_simple))
+       goto end_seq_and_fail;
+    }
 
   target = noce_emit_cmove (if_info, x, code, XEXP (if_info->cond, 0),
                            XEXP (if_info->cond, 1), a, b);
index e946a6f24dcb448095539e6d1920dc95cefd118c..05aa372288e7097a076bf909ef6b9aec816ed2a4 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-27  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       PR rtl-optimization/68506
+       * gcc.c-torture/execute/pr68506.c: New test.
+
 2015-11-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/63326
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68506.c b/gcc/testsuite/gcc.c-torture/execute/pr68506.c
new file mode 100644 (file)
index 0000000..15984ed
--- /dev/null
@@ -0,0 +1,63 @@
+/* { dg-options "-fno-builtin-abort" } */
+
+int a, b, m, n, o, p, s, u, i;
+char c, q, y;
+short d;
+unsigned char e;
+static int f, h;
+static short g, r, v;
+unsigned t;
+
+extern void abort ();
+
+int
+fn1 (int p1)
+{
+  return a ? p1 : p1 + a;
+}
+
+unsigned char
+fn2 (unsigned char p1, int p2)
+{
+  return p2 >= 2 ? p1 : p1 >> p2;
+}
+
+static short
+fn3 ()
+{
+  int w, x = 0;
+  for (; p < 31; p++)
+    {
+      s = fn1 (c | ((1 && c) == c));
+      t = fn2 (s, x);
+      c = (unsigned) c > -(unsigned) ((o = (m = d = t) == p) <= 4UL) && n;
+      v = -c;
+      y = 1;
+      for (; y; y++)
+       e = v == 1;
+      d = 0;
+      for (; h != 2;)
+       {
+         for (;;)
+           {
+             if (!m)
+               abort ();
+             r = 7 - f;
+             x = e = i | r;
+             q = u * g;
+             w = b == q;
+             if (w)
+               break;
+           }
+         break;
+       }
+    }
+  return x;
+}
+
+int
+main ()
+{
+  fn3 ();
+  return 0;
+}