The following patch fixes the missed handling of TRUTH_NOT_EXPR
predicates in predicate_mem_writes and general combined predicates
which need gimplification.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2012-04-13  Richard Guenther  <rguent...@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.

Index: gcc/tree-if-conv.c
===================================================================
--- gcc/tree-if-conv.c  (revision 186406)
+++ gcc/tree-if-conv.c  (working copy)
@@ -1543,11 +1522,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 +1546,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);
Index: gcc/testsuite/gcc.dg/torture/pr52969.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr52969.c      (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr52969.c      (revision 0)
@@ -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;
+}

Reply via email to