aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2015-12-10 22:29:12 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2015-12-10 22:29:12 +0000
commit428f139a54aeeb4fb1d186d2967346f84bcc6067 (patch)
tree3c1f47508c011352c3dd1b1727069ac6f6d2b6fe
parent0de496a6af9180f5e830ff8eba074875dd26b146 (diff)
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-5-branch@231546 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/ifcvt.c41
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr68376-2.c32
-rw-r--r--gcc/testsuite/gcc.dg/pr68670-1.c5
-rw-r--r--gcc/testsuite/gcc.dg/pr68670-2.c5
6 files changed, 69 insertions, 32 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8dda31a9c12..7697b85d8f4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+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-12-10 Andreas Tobler <andreast@gcc.gnu.org>
Backport from mainline
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index db07889a0f6..907977c32bb 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -2152,45 +2152,22 @@ noce_try_abs (struct noce_if_info *if_info)
Note that these rtx constants are known to be CONST_INT, and
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 but not
- x <= 0 ? ~x : x or x > 0 ? ~x : x, as the latter two
- have different result for x == 0. */
+ 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)
- {
- if (one_cmpl && negate)
- return FALSE;
- }
+ ;
else if (c == const1_rtx && GET_CODE (cond) == LT)
{
- if (one_cmpl && !negate)
+ if (one_cmpl)
return FALSE;
}
else if (c == CONST0_RTX (GET_MODE (b)))
{
- if (one_cmpl)
- switch (GET_CODE (cond))
- {
- case GT:
- if (!negate)
- return FALSE;
- break;
- case GE:
- /* >= 0 is the same case as above > -1. */
- if (negate)
- return FALSE;
- break;
- case LT:
- if (negate)
- return FALSE;
- break;
- case LE:
- /* <= 0 is the same case as above < 1. */
- if (!negate)
- return FALSE;
- break;
- default:
- return FALSE;
- }
+ if (one_cmpl
+ && GET_CODE (cond) != GE
+ && GET_CODE (cond) != LT)
+ return FALSE;
}
else
return FALSE;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cf8f5c95683..4d31cfa8df5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+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.
+
2015-12-10 Uros Bizjak <ubizjak@gmail.com>
Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68376-2.c b/gcc/testsuite/gcc.c-torture/execute/pr68376-2.c
index 884571a8923..963d441b53f 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr68376-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr68376-2.c
@@ -26,6 +26,30 @@ 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 ()
{
@@ -37,5 +61,13 @@ main ()
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
index 00000000000..92c28a0a4af
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr68670-1.c
@@ -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
index 00000000000..903e33e1f30
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr68670-2.c
@@ -0,0 +1,5 @@
+/* PR rtl-optimization/68670 */
+/* { dg-do run } */
+/* { dg-options "-O2 -ftracer" } */
+
+#include "../gcc.c-torture/execute/pr68376-2.c"