summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2012-04-27 12:20:01 +0000
committerPaolo Bonzini <bonzini@gcc.gnu.org>2012-04-27 12:20:01 +0000
commit809c929ccfeb2dfb3fdd19fd3bf5e540c778b4bc (patch)
tree50dc39dd31ef6d29a1116c582f05d381a88fc900 /gcc
parentd5548709911e5961c5cfbd4c32002815d98bc694 (diff)
downloadgcc-809c929ccfeb2dfb3fdd19fd3bf5e540c778b4bc.tar.gz
tree-ssa-phiopt.c (conditional_replacement): Replace PHIs whose arguments are -1 and 0...
2012-04-27 Paolo Bonzini <bonzini@gnu.org> * tree-ssa-phiopt.c (conditional_replacement): Replace PHIs whose arguments are -1 and 0, by negating the result of the conditional. testsuite: 2012-04-27 Paolo Bonzini <bonzini@gnu.org> * gcc.c-torture/execute/20120427-2.c: New testcase. * gcc.dg/tree-ssa/phi-opt-10.c: New testcase. * gcc.dg/tree-ssa/ssa-pre-28.c: Bypass new optimization. * gcc.dg/tree-ssa/ssa-ifcombine-7.c: Look into ifcombine dump. From-SVN: r186905
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20120427-2.c38
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c11
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-7.c6
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-28.c4
-rw-r--r--gcc/tree-ssa-phiopt.c26
7 files changed, 86 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 152bbe1f6a3..22411c2f0c3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
2012-04-27 Paolo Bonzini <bonzini@gnu.org>
+ * tree-ssa-phiopt.c (conditional_replacement): Replace PHIs
+ whose arguments are -1 and 0, by negating the result of the
+ conditional.
+
+2012-04-27 Paolo Bonzini <bonzini@gnu.org>
+
PR target/53138
* config/i386/i386.md (x86_mov<mode>cc_0_m1_neg): Add clobber.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0c41cc52e92..72f1f468456 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,12 @@
2012-04-27 Paolo Bonzini <bonzini@gnu.org>
+ * gcc.c-torture/execute/20120427-2.c: New testcase.
+ * gcc.dg/tree-ssa/phi-opt-10.c: New testcase.
+ * gcc.dg/tree-ssa/ssa-pre-28.c: Bypass new optimization.
+ * gcc.dg/tree-ssa/ssa-ifcombine-7.c: Look into ifcombine dump.
+
+2012-04-27 Paolo Bonzini <bonzini@gnu.org>
+
PR target/53138
* gcc.c-torture/execute/20120427-1.c: New testcase.
diff --git a/gcc/testsuite/gcc.c-torture/execute/20120427-2.c b/gcc/testsuite/gcc.c-torture/execute/20120427-2.c
new file mode 100644
index 00000000000..e473a4772a9
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20120427-2.c
@@ -0,0 +1,38 @@
+typedef struct sreal
+{
+ unsigned sig; /* Significant. */
+ int exp; /* Exponent. */
+} sreal;
+
+sreal_compare (sreal *a, sreal *b)
+{
+ if (a->exp > b->exp)
+ return 1;
+ if (a->exp < b->exp)
+ return -1;
+ if (a->sig > b->sig)
+ return 1;
+ if (a->sig < b->sig)
+ return -1;
+ return 0;
+}
+
+sreal a[] = {
+ { 0, 0 },
+ { 1, 0 },
+ { 0, 1 },
+ { 1, 1 }
+};
+
+int main()
+{
+ int i, j;
+ for (i = 0; i <= 3; i++) {
+ for (j = 0; j < 3; j++) {
+ if (i < j && sreal_compare(&a[i], &a[j]) != -1) abort();
+ if (i == j && sreal_compare(&a[i], &a[j]) != 0) abort();
+ if (i > j && sreal_compare(&a[i], &a[j]) != 1) abort();
+ }
+ }
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
new file mode 100644
index 00000000000..52b5942eb3a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int nem1_phi (unsigned long a) { return a ? -1 : 0; }
+int eqm1_phi (unsigned long a) { return a ? 0 : -1; }
+
+int spaceship1 (long a) { return a > 0 ? 1 : a < 0 ? -1 : 0; }
+int spaceship2 (long a) { return a > 0 ? 1 : a == 0 ? 0 : -1; }
+
+/* { dg-final { scan-tree-dump-times " = -D" 4 "optimized"} } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-7.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-7.c
index fd202509217..617cb585a94 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-7.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-7.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-options "-O -fdump-tree-ifcombine" } */
int test1 (int i, int j)
{
@@ -11,5 +11,5 @@ int test1 (int i, int j)
/* The above should be optimized to a i > j test by ifcombine. */
-/* { dg-final { scan-tree-dump " > " "optimized" } } */
-/* { dg-final { cleanup-tree-dump "optimized" } } */
+/* { dg-final { scan-tree-dump " > " "ifcombine" } } */
+/* { dg-final { cleanup-tree-dump "ifcombine" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-28.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-28.c
index 3c27a1a29f5..55887a694dc 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-28.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-28.c
@@ -6,7 +6,7 @@ int foo (int i, int b, int result)
{
int mask;
if (b)
- mask = -1;
+ mask = -2;
else
mask = 0;
result = i + 1;
@@ -15,7 +15,7 @@ int foo (int i, int b, int result)
}
/* We should insert i + 1 into the if (b) path as well as the simplified
- i + 1 & -1 expression. And do replacement with two PHI temps. */
+ i + 1 & -2 expression. And do replacement with two PHI temps. */
/* { dg-final { scan-tree-dump-times "with prephitmp" 2 "pre" } } */
/* { dg-final { cleanup-tree-dump "pre" } } */
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 798721993cd..88c16e68373 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -536,17 +536,21 @@ conditional_replacement (basic_block cond_bb, basic_block middle_bb,
gimple_stmt_iterator gsi;
edge true_edge, false_edge;
tree new_var, new_var2;
+ bool neg;
/* FIXME: Gimplification of complex type is too hard for now. */
if (TREE_CODE (TREE_TYPE (arg0)) == COMPLEX_TYPE
|| TREE_CODE (TREE_TYPE (arg1)) == COMPLEX_TYPE)
return false;
- /* The PHI arguments have the constants 0 and 1, then convert
- it to the conditional. */
+ /* The PHI arguments have the constants 0 and 1, or 0 and -1, then
+ convert it to the conditional. */
if ((integer_zerop (arg0) && integer_onep (arg1))
|| (integer_zerop (arg1) && integer_onep (arg0)))
- ;
+ neg = false;
+ else if ((integer_zerop (arg0) && integer_all_onesp (arg1))
+ || (integer_zerop (arg1) && integer_all_onesp (arg0)))
+ neg = true;
else
return false;
@@ -558,7 +562,7 @@ conditional_replacement (basic_block cond_bb, basic_block middle_bb,
falls through into BB.
There is a single PHI node at the join point (BB) and its arguments
- are constants (0, 1).
+ are constants (0, 1) or (0, -1).
So, given the condition COND, and the two PHI arguments, we can
rewrite this PHI into non-branching code:
@@ -585,11 +589,19 @@ conditional_replacement (basic_block cond_bb, basic_block middle_bb,
edge so that we know when to invert the condition below. */
extract_true_false_edges_from_block (cond_bb, &true_edge, &false_edge);
if ((e0 == true_edge && integer_zerop (arg0))
- || (e0 == false_edge && integer_onep (arg0))
+ || (e0 == false_edge && !integer_zerop (arg0))
|| (e1 == true_edge && integer_zerop (arg1))
- || (e1 == false_edge && integer_onep (arg1)))
+ || (e1 == false_edge && !integer_zerop (arg1)))
cond = fold_build1_loc (gimple_location (stmt),
- TRUTH_NOT_EXPR, TREE_TYPE (cond), cond);
+ TRUTH_NOT_EXPR, TREE_TYPE (cond), cond);
+
+ if (neg)
+ {
+ cond = fold_convert_loc (gimple_location (stmt),
+ TREE_TYPE (result), cond);
+ cond = fold_build1_loc (gimple_location (stmt),
+ NEGATE_EXPR, TREE_TYPE (cond), cond);
+ }
/* Insert our new statements at the end of conditional block before the
COND_STMT. */