summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-04-13 12:22:16 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-04-13 12:22:16 +0000
commit2df619414e5217ff59be65f8438003ddcfa70fdf (patch)
treea1b22ec581d09f617460923d197f29eb753d4509
parent7ad269265cd15f2d599829522f5a4ece45cdb23d (diff)
downloadgcc-2df619414e5217ff59be65f8438003ddcfa70fdf.tar.gz
2012-04-13 Richard Guenther <rguenther@suse.de>
PR tree-optimization/52969 * tree-if-conv.c (predicate_mem_writes): Properly gimplify the condition for the COND_EXPR and handle predicate negation by swapping the COND_EXPR arms. * gcc.dg/torture/pr52969.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186416 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr52969.c16
-rw-r--r--gcc/tree-if-conv.c17
4 files changed, 45 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c42ce67354a..7eee86a9dcc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-13 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/52969
+ * tree-if-conv.c (predicate_mem_writes): Properly gimplify
+ the condition for the COND_EXPR and handle predicate negation
+ by swapping the COND_EXPR arms.
+
2012-04-13 Nick Clifton <nickc@redhat.com>
* config/rl78/rl78.c (rl78_devirt_pass): Remove use of
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9abfbd3bded..f93259258af 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2012-04-13 Richard Guenther <rguenther@suse.de>
+ PR tree-optimization/52969
+ * gcc.dg/torture/pr52969.c: New testcase.
+
+2012-04-13 Richard Guenther <rguenther@suse.de>
+
PR c/52549
* gcc.dg/pr52549.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/torture/pr52969.c b/gcc/testsuite/gcc.dg/torture/pr52969.c
new file mode 100644
index 00000000000..05331d93f34
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr52969.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-ftree-loop-if-convert-stores" } */
+
+int a, b;
+float xsum[100];
+void foo (float *cluster)
+{
+ int j;
+ for (; a ; ++j) {
+ xsum[j] = cluster[j];
+ if (xsum[j] > 0)
+ xsum[j] = 0;
+ }
+ if (xsum[0])
+ b = 0;
+}
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 55616d57667..c86a4aa55bb 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -1543,11 +1543,19 @@ predicate_mem_writes (loop_p loop)
gimple_stmt_iterator gsi;
basic_block bb = ifc_bbs[i];
tree cond = bb_predicate (bb);
+ bool swap;
gimple stmt;
if (is_true_predicate (cond))
continue;
+ swap = false;
+ if (TREE_CODE (cond) == TRUTH_NOT_EXPR)
+ {
+ swap = true;
+ cond = TREE_OPERAND (cond, 0);
+ }
+
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
if ((stmt = gsi_stmt (gsi))
&& gimple_assign_single_p (stmt)
@@ -1559,6 +1567,15 @@ predicate_mem_writes (loop_p loop)
lhs = ifc_temp_var (type, unshare_expr (lhs), &gsi);
rhs = ifc_temp_var (type, unshare_expr (rhs), &gsi);
+ if (swap)
+ {
+ tree tem = lhs;
+ lhs = rhs;
+ rhs = tem;
+ }
+ cond = force_gimple_operand_gsi_1 (&gsi, unshare_expr (cond),
+ is_gimple_condexpr, NULL_TREE,
+ true, GSI_SAME_STMT);
rhs = build3 (COND_EXPR, type, unshare_expr (cond), rhs, lhs);
gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi));
update_stmt (stmt);