]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR rtl-optimization/68376 (wrong code at -O1 and above on x86_64-linux...
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Feb 2016 09:11:58 +0000 (10:11 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Feb 2016 09:11:58 +0000 (10:11 +0100)
Backported from mainline
2015-12-10  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/68376
PR rtl-optimization/68670
* ifcvt.c (noce_try_abs): For one_cmpl allow < 0, >= 0
or > -1 conditions regardless of negate, and disallow
all other conditions.

* gcc.c-torture/execute/pr68376-2.c (f5, f6, f7, f8): New
tests.
(main): Call them.
* gcc.dg/pr68670-1.c: New test.
* gcc.dg/pr68670-2.c: New test.

2015-11-19  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/68376
* ifcvt.c (noce_try_abs): Disable one_cmpl optimization if
encountering x <= 0 ? ~x : x or x > 0 ? ~x : x.

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

From-SVN: r233323

gcc/ChangeLog
gcc/ifcvt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr68376-1.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr68376-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr68670-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr68670-2.c [new file with mode: 0644]

index 091289fb107d4eaf52e7cf2aebf135d0ad899443..295408e4e7532cde39e7346ea8c2519848765d6a 100644 (file)
@@ -1,6 +1,20 @@
 2016-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2015-12-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/68376
+       PR rtl-optimization/68670
+       * ifcvt.c (noce_try_abs): For one_cmpl allow < 0, >= 0
+       or > -1 conditions regardless of negate, and disallow
+       all other conditions.
+
+       2015-11-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/68376
+       * ifcvt.c (noce_try_abs): Disable one_cmpl optimization if
+       encountering x <= 0 ? ~x : x or x > 0 ? ~x : x.
+
        2015-12-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/68680
index 2097de6820cd4fa13c0842f8dce77ac56651c425..ad436d7f97d5b8dd0f3b5c16a482847d7a6e7934 100644 (file)
@@ -2071,12 +2071,26 @@ noce_try_abs (struct noce_if_info *if_info)
 
   /* Work around funny ideas get_condition has wrt canonicalization.
      Note that these rtx constants are known to be CONST_INT, and
-     therefore imply integer comparisons.  */
+     therefore imply integer comparisons.
+     The one_cmpl case is more complicated, as we want to handle
+     only x < 0 ? ~x : x or x >= 0 ? x : ~x to one_cmpl_abs (x)
+     and x < 0 ? x : ~x or x >= 0 ? ~x : x to ~one_cmpl_abs (x),
+     but not other cases (x > -1 is equivalent of x >= 0).  */
   if (c == constm1_rtx && GET_CODE (cond) == GT)
     ;
   else if (c == const1_rtx && GET_CODE (cond) == LT)
-    ;
-  else if (c != CONST0_RTX (GET_MODE (b)))
+    {
+      if (one_cmpl)
+       return FALSE;
+    }
+  else if (c == CONST0_RTX (GET_MODE (b)))
+    {
+      if (one_cmpl
+         && GET_CODE (cond) != GE
+         && GET_CODE (cond) != LT)
+       return FALSE;
+    }
+  else
     return FALSE;
 
   /* Determine what sort of operation this is.  */
index 4a724f722b08934157b5e5354a1f31c7602cbb92..a146cb46680a7f20b8d6009b5d6fe35c6b05386c 100644 (file)
@@ -1,6 +1,20 @@
 2016-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2015-12-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/68376
+       PR rtl-optimization/68670
+       * gcc.c-torture/execute/pr68376-2.c (f5, f6, f7, f8): New
+       tests.
+       (main): Call them.
+       * gcc.dg/pr68670-1.c: New test.
+       * gcc.dg/pr68670-2.c: New test.
+
+       PR rtl-optimization/68376
+       * gcc.c-torture/execute/pr68376-1.c: New test.
+       * gcc.c-torture/execute/pr68376-2.c: New test.
+
        2015-12-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/68680
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68376-1.c b/gcc/testsuite/gcc.c-torture/execute/pr68376-1.c
new file mode 100644 (file)
index 0000000..cb52657
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR rtl-optimization/68376 */
+
+int a, b, c = 1;
+signed char d;
+
+int
+main ()
+{
+  for (; a < 1; a++)
+    for (; b < 1; b++)
+      {
+       signed char e = ~d;
+       if (d < 1)
+         e = d;
+       d = e;
+       if (!c)
+         __builtin_abort ();
+      }
+
+  if (d != 0)
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68376-2.c b/gcc/testsuite/gcc.c-torture/execute/pr68376-2.c
new file mode 100644 (file)
index 0000000..963d441
--- /dev/null
@@ -0,0 +1,73 @@
+/* PR rtl-optimization/68376 */
+
+extern void abort (void);
+
+__attribute__((noinline, noclone)) int
+f1 (int x)
+{
+  return x < 0 ? ~x : x;
+}
+
+__attribute__((noinline, noclone)) int
+f2 (int x)
+{
+  return x < 0 ? x : ~x;
+}
+
+__attribute__((noinline, noclone)) int
+f3 (int x)
+{
+  return x <= 0 ? ~x : x;
+}
+
+__attribute__((noinline, noclone)) int
+f4 (int x)
+{
+  return x <= 0 ? x : ~x;
+}
+
+__attribute__((noinline, noclone)) int
+f5 (int x)
+{
+  return x >= 0 ? ~x : x;
+}
+
+__attribute__((noinline, noclone)) int
+f6 (int x)
+{
+  return x >= 0 ? x : ~x;
+}
+
+__attribute__((noinline, noclone)) int
+f7 (int x)
+{
+  return x > 0 ? ~x : x;
+}
+
+__attribute__((noinline, noclone)) int
+f8 (int x)
+{
+  return x > 0 ? x : ~x;
+}
+
+int
+main ()
+{
+  if (f1 (5) != 5 || f1 (-5) != 4 || f1 (0) != 0)
+    abort ();
+  if (f2 (5) != -6 || f2 (-5) != -5 || f2 (0) != -1)
+    abort ();
+  if (f3 (5) != 5 || f3 (-5) != 4 || f3 (0) != -1)
+    abort ();
+  if (f4 (5) != -6 || f4 (-5) != -5 || f4 (0) != 0)
+    abort ();
+  if (f5 (5) != -6 || f5 (-5) != -5 || f5 (0) != -1)
+    abort ();
+  if (f6 (5) != 5 || f6 (-5) != 4 || f6 (0) != 0)
+    abort ();
+  if (f7 (5) != -6 || f7 (-5) != -5 || f7 (0) != 0)
+    abort ();
+  if (f8 (5) != 5 || f8 (-5) != 4 || f8 (0) != -1)
+    abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/pr68670-1.c b/gcc/testsuite/gcc.dg/pr68670-1.c
new file mode 100644 (file)
index 0000000..92c28a0
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR rtl-optimization/68670 */
+/* { dg-do run } */
+/* { dg-options "-O2 -ftracer" } */
+
+#include "../gcc.c-torture/execute/pr68376-1.c"
diff --git a/gcc/testsuite/gcc.dg/pr68670-2.c b/gcc/testsuite/gcc.dg/pr68670-2.c
new file mode 100644 (file)
index 0000000..903e33e
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR rtl-optimization/68670 */
+/* { dg-do run } */
+/* { dg-options "-O2 -ftracer" } */
+
+#include "../gcc.c-torture/execute/pr68376-2.c"